How to make a new List in Java
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Introduction
In Java, you do not instantiate the List interface directly. You create an object from a class that implements List, such as ArrayList or LinkedList, and usually store it in a List variable so your code depends on the interface rather than one concrete implementation.
The Most Common Pattern: ArrayList
For most cases, the default answer is ArrayList.
This is the common idiom:
- '
List<String>for the variable type' - '
new ArrayList<>()for the actual implementation'
That gives you flexibility to change the implementation later without changing most of the code that uses the list.
Why Use the Interface Type?
Writing List<String> fruits = new ArrayList<>(); is usually better than writing ArrayList<String> fruits = new ArrayList<>(); unless you need ArrayList-specific behavior.
The interface-based declaration makes the code less coupled to one implementation. If later you want LinkedList or another List implementation, fewer parts of the code need to change.
LinkedList Is Another Option
LinkedList also implements List.
It is often chosen when insertion and removal patterns matter more than fast indexed access, although in everyday application code ArrayList remains the more common default.
Create a List with Initial Values
Sometimes you want a list that starts with known elements. One traditional approach is:
In modern Java, List.of(...) is often cleaner when you want an immutable list.
The key difference is mutability. List.of(...) creates an unmodifiable list, so add() and remove() are not allowed on it.
Mutable Versus Immutable Lists
This distinction matters a lot:
- '
new ArrayList<>()gives you a mutable list' - '
List.of(...)gives you an unmodifiable list'
If you write:
you will get an exception at runtime. So choose the creation style based on whether the list should change after creation.
Copying an Existing List
Another common way to make a new list is to copy an existing one into a mutable implementation.
This is useful when you want the convenience of List.of(...) as input but still need a list you can modify later.
Choose the Implementation by Use Case
A simple rule works well:
- use
ArrayListby default - use
LinkedListonly when you have a reason - use
List.of(...)when you want a small fixed list
That keeps code readable and avoids premature optimization. Many Java programs work perfectly well with ArrayList unless profiling or a special usage pattern suggests otherwise.
Common Pitfalls
The most common mistake is trying to instantiate List directly with new List<>(), which does not work because List is an interface. Another is forgetting that List.of(...) returns an unmodifiable list and then trying to call add() or remove(). Developers also sometimes declare variables with a concrete implementation type when the interface type would make the code more flexible for no extra cost.
Summary
- Create a
Listby instantiating an implementing class such asArrayList. - The usual pattern is
List<Type> list = new ArrayList<>();. - Use
LinkedListonly when its behavior is a better fit for the problem. - Use
List.of(...)for concise unmodifiable lists. - Prefer the
Listinterface in variable declarations unless you need implementation-specific features.
Related reading
- How to make lists contain only distinct element in Python?
- How to make print call the __str__ method of Python objects inside a list?
- How to make RabbitMQ queues failover?
- how to manage an NDC-like log4net stack with async/await methods? per-Task stack?
- How to make asynchronous tasks have lower priority in Java 8?
- how to make auto reload with Spring-boot on IDEA Intellij
- How to map hashfunction output to bloomfilter indices?
- How to master in-place array modification algorithms?

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.