neelam
neelam

Reputation: 39

how to add specific element to the array of arraylist

ArrayList<int[]> arl = new ArrayList<int[]>();
int a1[] = {1, 2, 3};
arl.add(0, a1);

How do I set an element value at a specific position like we do in 2d array as ar1[0][2]=5 in this code if we want to reset the value 3 to something else.

Upvotes: 0

Views: 78

Answers (1)

Mikhail Vladimirov
Mikhail Vladimirov

Reputation: 13900

Define you arl as

ArrayList <int []> arl = new ArrayList <int []> ();
arl.add (0, new int [] {1, 2, 3});

and do like this:

arl.get (0) [2] = 5;

Upvotes: 2

Related Questions