E represents an Element, which could be any class. For example, if you're building an array list of Integers then you'd initialize it as -
You replace "Integer" with the class that the list is of.
ensureCapacity is used
E represents an Element, which could be any class. For example, if you're building an array list of Integers then you'd initialize it as -
You replace "Integer" with the class that the list is of.
ensureCapacity is used to ensure that the list has enough capacity to take in the new elements. It's called internally every time you add a new item to the list. As the name suggests, ArrayList uses an Array to store the items. So when the array is initialized, it's given an arbitrary length, say 10. Now once you've added 10 items, if you go to add