Code for static initializer exceeds error limit of 65535 bytes in java?

Hi, I am trying to initialize 4 string arrays with a length of 10.1 billion and these arrays are similar to
array1={"0","1",..."9"} 
array2={"00","01",..."99"} 
array3={"000","001",..."999"} 
array4={"0000","0001",..."9999"} 

But I get an error . Code for static initializer exceeds 65535 bytes limit

how can i initialize my arrays?

Also note that downloading it from a file is not an option for me :(

+3
source share
3 answers

in - java, . . jvm 65535 , 16- .

, , :

static {
    array1 = getValuesForArray1();
    ...
}

private static String[] getValuesForArray1() {
    ...
}

, , , " ".

+7

for. :

for (int i = 0; i <= 9; i++)
    array1[i] = String.valueOf(i);
+7

Perhaps this is best solved by writing a method that takes an int argument and returns the string value that would be in this array index. Here it uses String.format and indicates the length of the remaining fill:

private static String getValue(int index, int stringLength) {
    return String.format("%0" + stringLength + "d", index);
}
+2
source

All Articles