• Register
0 votes

Problem :

I am getting bellow error while compiling Arraylist

exception in thread "main" java.lang.indexoutofboundsexception: index: 0, size: 0

by (6.9k points)  
edited by

1 Answer

0 votes


It seems "ArrayList<ArrayList<Integer>> " this list doesnt have any element at the (0)th postion and now the compiler throws "out of bounds exception" as it doesn't find any element in that postion.

when you try executing bellow code

list.get(0).set(placeHolder.get(k), (int) (Math.random() * (99999) + 1)); 

 your list is empty so you need to iterate through the inner list to set the values for the list.

Further Readings:


by (36.1k points)  
edited by