When we create an ArrayList and check its size, it gives the value as 0. However, when we add an element and remove that element, and then check its size, it throws exception.
What is the internal implementation in remove() method, that it changes the definition of an empty list?
Code below gives output as 0.
List<Integer> list2 = new ArrayList<Integer>();
System.out.println(list2.size());
Code below throws Exception:
List<Integer> list1 = new ArrayList<Integer>();
list1.add(1);
System.out.println(list1.size());
list1.remove(1);
System.out.println(list1.size());