How to Store Integers, Doubles, etc. in ArrayList in Java
You may be reading this post because you are trying to do something like the following code, which isn’t allowed in Java because int is a “primitive type”:
ArrayList<int> intList = new ArrayList<int>();
intList.add(1);
intList.add(2);
The short answer is to use syntax such as the following:
ArrayList<Integer> intList = new ArrayList<Integer>();
intList.add(1);
intList.add(2);
for (int i : intList)
System.out.println(i);
Now for [...] Read more »