I’m looking for the “right” way to fix a problem with an array in Java:
i need an array for integers, without knowing the max value.
current solution for bypassing the limit on declaration:
private ArrayList<Integer> myArray = new ArrayList<>();
problem with this solution:
myArray.get(i);
wants to return a String instead of an int, and I need the int for further calculations…
Should i go with something else than an ArrayList or am i missing something else ?
(i’m guessing the last option…)
Yes, since you don’t know how many items you want your array to hold, you should indeed use an
ArrayList. FurthermoremyArray.get(i)will indeed return anint, just try