My code of adding elements through ArrayList :
public class ArrayList2 {
//Delete all ArrayList using Collection remove method
public static void main(String[] args) throws IndexOutOfBoundsException{
ArrayList<Integer> list = new ArrayList<Integer>();
/*list.add(10);
list.add(20);*/
list.add(30);//Addition using add(int index,Object element) method
list.add(40);
list.add(50);
list.add(4,60);
list.add(70);
list.add(80);
System.out.println("Size of list "+ list.size());
System.out.println("Initial list "+ list);
}
}
I tried to use Collections add method add(Object) and Lists add method add(Int index, Object o) to add elements.But when I use the above code error is thrown