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, LinkedList, and vector are the three classes that implement this interface. This interface provides a set of methods. It exposes a few methods, whereas these three classes use these methods in their classes.

Out of these three, let's discuss ArrayList. This is one of the most famous ones, and is used by most Java programmers. Once you understand ArrayList, you can easily figure out LinkedLists and vector. In the next section, we will create an ArrayList class and implement methods present in the List interface, to see how flexible these methods are at retrieving or organizing data. When you have a set of data in a container, you can easily organize that data with the help of the List interface.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.100.34