ArrayList of int array in java
To create an ArrayList of int
arrays in Java, you can use the following syntax:
List<int[]> list = new ArrayList<>();
This creates an ArrayList that can hold arrays of int
values. You can add an int
array to the list using the add
method:
int[] array = {1, 2, 3};
list.add(array);
You can also create an ArrayList of Integer
objects, which allows you to use the add
and get
methods of the ArrayList class to add and retrieve Integer
values, respectively.
List<Integer> list = new ArrayList<>();
list.add(1);
list.add(2);
list.add(3);
int value = list.get(0); // value is 1
I hope this helps! Let me know if you have any questions.