bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths

Loading lesson path

Learn/Java/Java Data Structures
Java•Java Data Structures

Java List

Java List Interface

The List interface is part of the Java Collections Framework and represents an ordered collection of elements.

You can access elements by their index, add duplicates, and maintain the insertion order.

Since List is an interface, you cannot create a List object directly.

Instead, you use a class that implements the List interface, such as:

  • ArrayList - like a resizable array with fast random access
  • LinkedList - like a train of cars you can easily attach or remove

Tip

Use List when you care about order, you may have duplicates, and want to access elements by index.

Common List Methods

MethodDescription
add()Adds an element to the end of the list
get()Returns the element at the specified position
set()Replaces the element at the specified position
remove()Removes the element at the specified position
size()Returns the number of elements in the list

List vs. Array

ArrayList
Fixed sizeDynamic size
Faster performance for raw dataMore flexible and feature-rich
Not part of Collections FrameworkPart of the Collections Framework

In the next chapters, you will learn how to use ArrayList and LinkedList .

Previous

Java Collections Framework

Next

Java ArrayList