A Collection is a group of individual objects represented as a single unit. Java provides Collection Framework which defines several classes and interfaces to represent a group of objects as a single unit This framework consists the List Interface as well as the ArrayList class. In this article, the difference between the List and ArrayList is discussed.
List: The List is a child interface of Collection. It is an ordered collection of objects in which duplicate values can be stored. Since List preserves the insertion order, it allows positional access and insertion of elements. List interface is implemented by the classes of ArrayList, LinkedList, Vector and Stack. List is an interface, and the instances of List can be created by implementing various classes. The following is an example to demonstrate the implementation of a list:
[Geeks, For, Geeks]
ArrayList: ArrayList is a part of collection framework and is present in java.util package. It provides us with dynamic arrays in Java. This class implements the List interface. Similar to a List, the size of the ArrayList is increased automatically if the collection grows or shrinks if the objects are removed from the collection. Java ArrayList allows us to randomly access the list. ArrayList can not be used for primitive types, like int, char, etc. We need a wrapper class for such cases. The following is an example to demonstrate the implementation of an ArrayList:
[Geeks, For, Geeks]
List vs ArrayList in Java
|List is an Interface.||ArrayList is a Class.|
|List interface extends the Collection framework.||ArrayList extends AbstractList class and implements List interface.|
|List cannot be instantiated.||ArrayList can be instantiated.|
|List interface is used to create a list of elements(objects) which are associated with their index numbers.||ArrayList class is used to create a dynamic array that contains objects.|
|List interface creates a collection of elements that are stored in a sequence and they are identified and accessed using the index.||ArrayList creates an array of objects where the array can grow dynamically.|
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- ArrayList of ArrayList in Java
- Java Collection| Difference between Synchronized ArrayList and CopyOnWriteArrayList
- Difference between length of Array and size of ArrayList in Java
- Difference between ArrayList and HashSet in Java
- Difference between ArrayList and CopyOnWriteArrayList
- Java.util.ArrayList.add() Method in Java
- Java.util.ArrayList.addall() method in Java
- Java.util.Arraylist.indexOf() in Java
- ArrayList and LinkedList remove() methods in Java with Examples
- Find first and last element of ArrayList in java
- Get first and last elements from ArrayList in Java
- Array vs ArrayList in Java
- ArrayList in Java
- ArrayList vs LinkedList in Java
- How to remove an element from ArrayList in Java?
- ArrayList to Array Conversion in Java : toArray() Methods
- Vector vs ArrayList in Java
- Conversion of Array To ArrayList in Java
- Synchronization of ArrayList in Java
- Custom ArrayList in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.