How do you assign values to ArrayList<int[]>
, like you do with 2D array anArray[0][0] = val
?
6 Answers
you can use set
as described here
Vector<int[]> v = new Vector<int[]>[10];
v.set(0, new int[10]);
and then get a value
int[] curr = c.get(0);
you can add elements to arraylist using add metheod.
int[] x={1,2,3,4,5};
ArrayList<int[]> demo = new ArrayList<int[]>();
demo.add(x);
you can, inserts the specified element at the specified position in this list.
add(int index, E element)
index : index at which the specified element is to be inserted. element element to be inserted here must be integer array
demo.add(5, x);
element inserted in 5th position in arraylist