The List collection
The first one is the List
collection/interface. A list is an ordered collection, sometimes we call it as a sequence as well. Lists may contain duplicate elements, just like arrays, but there are lots of differences between an array and ArrayList
. You can insert multiple values into this List
container, and it might contain duplicate elements as well. You can actually add any value and remove any value from any index. Let's say you added 15 elements sequentially into the list, now you want to remove 6th element, or you want to insert an element between the 10th and 11th elements, or you want to know an element at what index it is out of those 15 elements. There are lots of helpful APIs to retrieve elements from the list container, which we don't get in arrays. Arrays can only be initialized; apart from that, you cannot perform any methods on an array, whereas with ArrayList
you have lots of flexible methods to play around with.
The List
interface is a collection, and ArrayList...