List vs ArrayList in Java

Collections.unModifiableList()in Java

Amar Balu
The Fresh Writes

--

Java is a popular programming language that provides developers with an extensive set of tools for creating robust applications. One of the most powerful features of Java is its collection framework, which provides a set of classes and interfaces for storing and manipulating collections of objects. In this article, we will explore two important components of the Java collection framework: the List interface and the ArrayList collection.

Photo by Clément Hélardot on Unsplash

The List Interface in Java The List interface in Java is a subinterface of the Collection interface, and it defines an ordered collection of elements that allows duplicates. This means that elements in a List are stored in a specific order and can be accessed using an index. The List interface also provides methods for adding, removing, and modifying elements in the list.

Here is an example of how to create a List and add elements to it using Java code:

List<String> mylist = new ArrayList<String>();
mylist.add("apple");
mylist.add("banana");
mylist.add("cherry");

In this example, we create an empty ArrayList of Strings and add three elements to it using the add() method.

The ArrayList Collection in Java The ArrayList collection in Java is one of the most commonly used…

--

--

Amar Balu
The Fresh Writes

I'm a front-end developer. I love React and Redux, Java, and Data Science. I write code for fun!. Join our publication : https://medium.com/thefreshwrites