An int[]
array maps most naturally to a List<Integer>
. Unfortunately, there is no built-in way to convert directly from an int
array to an Integer
list, due to the boxing that is required. You'll have to build the List
manually.
int[] things = {11, 22, 33, 44};
List<Integer> list = new ArrayList<>();
for (int i: things) {
list.add(i);
}
int n = list.get(1);
System.out.println(n);
The excellent Guava library from Google has a convenience method you could use, if you're willing to rely on a third-party library call.
int[] things = {11, 22, 33, 44};
List<Integer> list = Ints.asList(things);
int n = list.get(1);
System.out.println(n);
Or if your goal is simply to get a List
of numbers, you could skip the intermediate array.
List<Integer> list = Arrays.asList(11, 22, 33, 44);