How can I initialize an integer array in Java, for example: int[] array = {1,2,3};inside a switch statement?
Currently I can write:
switch(something) {
case 0: int[] array = {1,2,3}; break;
default: int[] array = {3,2,1};
}
But when I try to access a variable array, eclipse will complain that it cannot be initialized.
If I try to declare it as int[] array;or int[] array = new int[3];, and then the switch statement, I would say that I am trying to update it.
How can I solve this problem? The final idea is to be able to initialize an array with 10 values in one line of code based on some logic (switch statement).
source
share