Java Collections Framework: Methods & Algorithms

InstructorEdward Lavieri

Ed has created and taught college courses since 2002 and has a Doctorate of Computer Science and three MS degrees. He has authored several tech books.

We can use collections of interfaces, implementations, and algorithms in Java to make our code more efficient and to save development time. This concept is based on the Java Collections Framework. Updated: 02/11/2025

Java is a mature programming platform that includes a collections framework. This framework is a collection of Java language components that has a set of common behaviors, which is a mandate of Java collections. The Java collections framework contains interfaces, implementations, and algorithms.

The benefits of using collections include:

To unlock this lesson you must be a Study.com Member.
Create your account

The List interface extends the Collections framework as well as the Iterable interface.

Java Collections Framework - List Interface
Java Collections Framework

The List interface has over 2 dozen native methods as well as the methods it inherits from the Collection and Iterable interfaces.

Working with Lists

To show how to work with the List interface, we will start by creating an ArrayList and adding values to the first four positions (0, 1, 2, and 3) using the add() method:

List<String> myList = new ArrayList<>();
myList.add('This');
myList.add('makes');
myList.add('no');
myList.add('sense');

We can retrieve a single element from the ArrayList by using the get() method.

System.out.println(myList.get(1));

Next, we will replace one of the values and then iterate through the ArrayList to print it to the console.

myList.set(2, 'perfect');
for (String theValue : myList) {
System.out.print(theValue + ' ');
}

Executing this code results in the following output: This make perfect sense

Searching and Sorting Lists

Searching and sorting are common operations for Lists. To demonstrate, let's create an ArrayList to hold names:

List<String> listOfNames = new ArrayList<>();
listOfNames.add('jimmy');
listOfNames.add('sally');
listOfNames.add('cindy');
listOfNames.add('rhona');
listOfNames.add('john');
listOfNames.add('brenda');
listOfNames.add('lona');

Our list consists of 7 names. We will perform three operations on this list: search, sort, and change the names so their first letter is capitalized. One step at a time, let's search our list to see if we can find Brenda:

if (listOfNames.contains('brenda')) {
System.out.println('Record found!');
}
else {
System.out.println('Record not found!');
}

To unlock this lesson you must be a Study.com Member.
Create your account

Java affords us the opportunity to work on a collection of interfaces, implementations, and algorithms, which is referred to as a collections framework. These collections enable us to write more efficient code quickly and to promote code portability. The List interface extends the Collections framework with 10 implemented classes including ArrayList. In addition, the List interface includes over 2 dozen methods that allow us to perform add, update, remove, search, and other element manipulation operations.

To unlock this lesson you must be a Study.com Member.
Create your account

Register to view this lesson

Are you a student or a teacher?

Unlock Your Education

See for yourself why 30 million people use Study.com

Become a Study.com member and start learning now.
Become a Member  Back

Resources created by teachers for teachers

Over 30,000 video lessons & teaching resources‐all in one place.
Video lessons
Quizzes & Worksheets
Classroom Integration
Lesson Plans

I would definitely recommend Study.com to my colleagues. It’s like a teacher waved a magic wand and did the work for me. I feel like it’s a lifeline.

Jennifer B.
Teacher
Jennifer B.
Create an account to start this course today
Used by over 30 million students worldwide
Create an account
close