I have an Arraylist of integers. My requirement is to determine if the arraylist HAS an element existing at the specified index.If YES, then a value should be set to that in
set method replaces the element in the specified position with the new element. But in add(position, element) will add the element in the specified position and shifts the existing elements to right side of the array .
ArrayList al = new ArrayList();
al.add("a");
al.add(1, "b");
System.out.println(al);
al.set(0, "c");
System.out.println(al);
al.add(0, "d");
System.out.println(al);
---------------Output -------------------------------------
[a, b]
[c, b]
[d, c, b]