List vs. ArrayList in Java

The difference between list and ArrayList in Java is that list is an interface in Java which extends the collection framework whereas ArrayList in Java is collection classes which abstract AbstartList classes.

Advertisement - Continue Reading Below
List vs. ArrayList in Java

Java is a programming language that is used a lot; Java is an object-oriented programming language that uses both compiler and interpreter. Mostly all software’s are made in Java programming language. Java code can be written on Windows, Linux, and Mac OS. The syntax of C and C++ programming language is quite the same. Java produces browser to run programs that help in making a graphical user interface. List and ArrayList are two important concepts in java because Java programming language is in used and trend these days. If we talk about the main difference, then the main difference between list and ArrayList in Java is that List is an interface in Java which extends the collection framework whereas ArrayList in Java is collection classes which abstract AbstartList classes.

Advertisement - Continue Reading Below

To write Java code, a programmer needs software development kit (SDK) that includes a compiler, interpreter that is not required in C++.  Java programming language does not support multiple inheritances. Java programming language has no interaction to hardware. Java programming language does not support the call by reference. In Java list and ArrayList are members of the collection framework. List are elements in a sequence, elements of a list are accessed by the position that is index.

Contents: Difference between List and ArrayList in Java

Comparison Chart

Basis List ArrayList
Meaning The list is an interface in Java which extends the collection framework ArrayList in Java is collection classes which abstract AbstartList classes. 
Syntax The list is interface list ArrayList is class ArrayList
Namespace System.Collections.Generic. System.Collections.
Working List create elements that are associated with the index. ArrayList create a dynamic array
Advertisement - Continue Reading Below

 List

List in Java programming is an interface that extends the collection framework. List create a collection of elements, arranged in sequential order. The list is created by using following classes

  • ArrayList
  • LinkedList
  • CopyOnWriteArrayList
  • Vector
  • Stack

In the list, elements are associated with the indexes, if you want to access an element, you can access it by using the index of that number. Two methods of list interface are added (int, E) and addAll(int, Collection). There are three types of exceptions in the list that are

  • UnsupportedOperationException
  • ClassCastException
  • NullPointerException

If we want to obtain an element after making a list in Java, you can use get() method.

ArrayList

ArrayList is a collection of classes which extends AbstactList class. ArrayList also implements list interface. ArrayList create dynamic arrays. ArrayList create an array of objects. The array has fixed length in ArrayList. There is a fixed length of the array in Java.   The capacity of the object of class ArrayList increase, when elements are added to the array. ensureCapacity() we used to increase the capacity of ArrayList.

Advertisement - Continue Reading Below

Key Differences

  1. List is an interface in Javawhich extends the collection framework whereas ArrayList in Java is collection classes which abstract AbstartList classes.
  2. The list is interface list whereas ArrayList is class ArrayList.
  3. In list System.Collections.Generic, whereas in ArrayList System. Collections.
  4. List create elements that are associated with index whereas ArrayList create a dynamic

Conclusion

In this article above we see the clear difference between List in Java and ArrayList in java with implementation.

Explanatory Video

Advertisement - Continue Reading Below

Leave a Comment