bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
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

This chapter

Overview
16

Lessons

58m

Read time

1. Java Data Structures2. Java Collections Framework3. Java List4. Java ArrayList5. Java LinkedList6. Java List Sorting7. Java Set8. Java HashSet9. Java TreeSet10. Java LinkedHashSet11. Java Map12. Java HashMap13. Java TreeMap14. Java LinkedHashMap15. Java Iterator16. Java Algorithms

On this page

Java List InterfaceCommon List MethodsList vs. Array