I'm not too familiar with the "Array" in java. But if you don't need an ArrayList, why not make an array of ints?
Ex:
1 2 3 4 5 6 7 8 9 10 11
| private int[] array = new int[10]; private int[][] array2 = new int[5][5]; for(int i=0; i < array.size(); i++) { array[i] = i*i; }
int num1 = array[1]; int num2 = array[2];
system.out.println(num1 + "," + num2) |
But once allocated arrays can't change in size. That's why you can use the ArrayList class which changes its size automatically for you if needed. And it also comes with a lot of helpful methods for handling the data inside.
The "<>" inbetween the ArrayList is what's called a "Generic" iirc, it just tells the compiler what kind of Objects you intend on using the ArrayList for so that if you by mistake put something else in there it will notify you.
Of course, you can use the Object as the generic type to make it store ANY kinds of objects. You can then internally check what kind of objects it holds with the "instanceof" keyword.
Ex:
1 2 3 4 5 6 7 8 9
| ArrayList<Object> list = new ArrayList<Object>(10); list.add( new String("Hello") ); list.add( new Integer(3) );
for (int i=0; i < list.size(); i++) { Object data = list.get(i); if (data instanceof String) System.out.println( data ); } |
Please note though that the above method of using instanceof in its current state isn't really recommended, just as an example to demystifying the generic <> tag :P
"Anytime you find yourself writing code of the form "if the object is of type T1, then do something, but if it's of type T2, then do something else," slap yourself."