Java array with around 20000 values declaration -


i encounter issue java array around 20000 values,

full array can found here

my code:

public class usableids {      private final static int idsarray[] = {615,616,617,618,...};     private final static int ids = idsarray.length;      public static string checkid(int x){         for(int i=0;i<ids;i++){             if(x==idsarray[i])                 return "usable";         }         return "notusable";     } } 

in other method try call with:

string temp = usableids.checkid( xyz ); 

here @ point program crash crash

i use netbeans.

i'll happy if can me piece of code running.

you seeing error because java limits size of static initializer blocks 65535 bytes. best separate data source code, i.e. put ids separate file.

the below code equivalent yours, assuming data within array stored (comma-separated, without brackets or line breaks) /temp/usableids.txt.

import java.nio.file.files; import java.nio.file.paths;  public class usableids {      private final static int idsarray[];      static {         try {             string filedata = new string(                 files.readallbytes(paths.get("/temp/usableids.txt")), "utf-8").trim();             string[] ids = filedata.split(",");             idsarray = new int[ids.length];              (int = 0; < ids.length; i++) {                 idsarray[i] = integer.parseint(ids[i]);             }          } catch (exception e) {             throw new runtimeexception(e);         }     }      public static string checkid(int x) {         (int = 0; < idsarray.length; i++) {             if (x == idsarray[i])                 return "usable";         }         return "notusable";     } } 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -