Collections in Java Part III : List

Hello Friends,

This is part III for java collections tutorial. Earlier we have discussed regarding SET collection interface in part II. In this, we will be focusing on an interface that is used when the sequence of the elements needs to be maintained, yes that’s right its LIST interface. List interface in Java Collection Framework also extends the base interface, Collection. 

List interface extends the Collection Interface itself.  The List interface has precise control over where each element is inserted. One can access elements by their integer index (position), and search for elements in the list. Unlike Set interface, it allows duplicates

The List interface is further implemented by the classes Vectors, ArrayList and LinkedList. We will see each of these implementations in details.

1) ArrayList : It is an resizable-array implementation of the List interface. It implements all the operations of List, and permits all elements, including null. This class provides methods to manipulate the size of the array that is used internally to store the list. By default, all the new elements that are added to arraylist are added to last position, else you can mention the position(index). As elements are added to an ArrayList, its capacity grows automatically by half of its original size. The most important point with ArrayList is that it is not Synchronized.

2) LinkedList : It is the Linked List implementation of List Interface. It also implements all the operations of List and also permits null.  the LinkedList class provides uniformly named methods to get, remove and insert an element at the beginning or end of the list. These operations allow linked lists to be used as a stack, queue, or double-ended queue (deque). Like ArrayList, its implementation is also not synchronized.

3) Vectors : Vectors class implements a growable array of objects. Like an array, it contains components that can be accessed using an integer index. However, the size of a Vector can grow its size to double when element insertion reaches at last. Its implementation is very much similar to ArrayList, only change is that Vectors are Synchronized. And since it is synchronized, it is slower that ArrayList, but is Thread safe.

Hope this will help you.

Thanks,

Nikhil Naoghare

Related Posts

  • Abstract Class In JAVA

    Hello Friends, This tutorial is for all the Java followers. One of the best feature that is widely used is the term ‘Abstract’. This term can be used as either class or a simple method. An abstract method is any method that is just declared but not instantiated. In other words one can just create…

  • Threads in Java.

    Hello Friends, This is the tutorial for the java developers. One of the most significance feature of core java is Threading. Threading deals with the processing of Threads in a single java program. Let us learn what actually are Threads. *What are Threads? Threads are independently running processes that are isolated from each other upto…

  • Collections In Java.

    Hello friends, Welcome to another tutorial for java followers. You all may have heard about Collections, it is one of the amazing feature in java. Collections are the object for the group of elements, these elements are nothing but the different data structures like as Array Lists, Linked Lists, Vectors, Hash tables,Hash List, Trees, Hash…

  • Java Date Format.

    Hello Friends, This is one of my tutorials regarding java Date format / object in Java. Many of us find it difficult to store the current date from the java application in database. Lets consider MySql as a database in this case. Now when we create a row in the database table that stores date…

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.