Java LinkedList Methods

Beginner
6 min read
Updated: Nov 2026
44 method guides
Method index

About This Index

This page is the Java LinkedList Methods index. Each row links to a full guide with syntax, parameters, return value, three runnable examples, and FAQs. Every example is a complete Java class with a main method and fixed data, and all of them compile on Java 8 and later.

New to LinkedList? It is a doubly-linked list from the java.util package, so you write import java.util.LinkedList; first. Every element sits in its own node that points to the node before and the node after it. That makes adding or removing at the front or back very fast, while get(i) has to walk node by node. LinkedList is both a List and a Deque, so you can use it as a list with add() and remove(), or as a queue or stack with poll() and push(). It allows duplicates and null.

List, Deque, or Queue?

Methods like addFirst(), getLast(), poll(), and pop() come from Deque and Queue, so declare your variable as LinkedList to use them: LinkedList<String> names = new LinkedList<>();. A plain List variable only sees the list methods. Also remember that on a LinkedList<Integer>, remove(1) removes the element at index 1, not the number 1.

How to Call a LinkedList Method

Create a LinkedList, then call each method on the variable:

Java
import java.util.LinkedList;

LinkedList<String> queue = new LinkedList<>();
queue.add("Ana");                // append:  [Ana]
queue.addFirst("Zed");           // front:   [Zed, Ana]
queue.addLast("Bo");             // back:    [Zed, Ana, Bo]

String head = queue.getFirst();  // "Zed", still in the list
String next = queue.poll();      // removes and returns "Zed"
int count = queue.size();        // 2

Java LinkedList Methods Table

All method guides in this Java tutorial series (44 tutorials), grouped by purpose.

Add elements

8 methods

Put a new element at the end, at the front, or at an index, one at a time or a whole collection at once. Includes the queue-style offer methods and the stack-style push.

MethodDescriptionTutorial
add()Append an element to the end, or insert it at an index.Try it
addAll()Append every element of another collection, or insert them at an index.Try it
addFirst()Insert an element at the front (head) of the list.Try it
addLast()Insert an element at the end (tail) of the list.Try it
offer()Add an element to the tail of the queue and return true.Try it
offerFirst()Insert an element at the front and return true.Try it
offerLast()Insert an element at the tail and return true.Try it
push()Push an element onto the front of the list, like a stack.Try it

Read without removing

7 methods

Look at an element by index, or at the first or last one, without taking it out of the list. Some methods throw on an empty list and some return null.

MethodDescriptionTutorial
get()Read the element at a given index.Try it
getFirst()Read the first element, or throw if the list is empty.Try it
getLast()Read the last element, or throw if the list is empty.Try it
element()Read the head of the queue, or throw if it is empty.Try it
peek()Look at the head without removing it; null if empty.Try it
peekFirst()Look at the first element without removing it; null if empty.Try it
peekLast()Look at the last element without removing it; null if empty.Try it

Remove one element

9 methods

Take out the first, the last, or a chosen element, by index or by value. The poll methods return null on an empty list, the others throw.

MethodDescriptionTutorial
remove()Remove the head, the element at an index, or the first match.Try it
removeFirst()Remove and return the first element, or throw if empty.Try it
removeLast()Remove and return the last element, or throw if empty.Try it
poll()Remove and return the head, or null if the list is empty.Try it
pollFirst()Remove and return the first element, or null if empty.Try it
pollLast()Remove and return the last element, or null if empty.Try it
pop()Pop the top element of the stack, or throw if it is empty.Try it
removeFirstOccurrence()Remove the first element equal to a value, searching from the head.Try it
removeLastOccurrence()Remove the last element equal to a value, searching from the tail.Try it

Remove many and clear

4 methods

Remove every element that matches a collection or a condition, keep only the common ones, or empty the whole list.

MethodDescriptionTutorial
removeAll()Remove every element that also appears in another collection.Try it
retainAll()Keep only the elements that also appear in another collection.Try it
removeIf()Remove every element that passes a test, using a lambda.Try it
clear()Remove every element, leaving an empty list.Try it

Loop, view, and copy

8 methods

Walk through the list with iterators, forEach, or a spliterator, look at a slice with subList, and copy the elements to an array or to a new list.

MethodDescriptionTutorial
iterator()Walk the list from the first element to the last, one at a time.Try it
listIterator()Get an iterator that moves both ways and can add or replace elements.Try it
descendingIterator()Walk the list from the last element to the first.Try it
forEach()Run a piece of code for every element, using a lambda.Try it
spliterator()Get a Spliterator, the traversal tool used by Java streams.Try it
subList()Get a live view of a range of the list.Try it
toArray()Copy the elements of the list into an array.Try it
clone()Make a shallow copy of the list.Try it

Frequently Asked Questions

They are the methods of java.util.LinkedList, a doubly-linked list that is both a List and a Deque. They add, read, change, search, and remove elements, loop over them, and copy or convert the list, from either end or at any index.
This index lists 44 guides, grouped by what they do. Start with add(), get(), and remove(). Then try addFirst(), poll(), and iterator() to see how a LinkedList works as a queue and a list.
Use LinkedList when you add or remove at the front or back all the time, such as a queue. Use ArrayList when you read by index a lot, because get(i) on a LinkedList has to walk node by node from one end, which is slow on long lists.
Methods such as addFirst(), getLast(), removeFirst(), push(), pop(), peek(), poll(), and offer() come from Deque and Queue. Declare the variable as LinkedList (or Deque, or Queue) to use them, because a plain List variable does not have them.
forEach(), removeIf(), replaceAll(), sort(), and spliterator(). Every other method here works on older versions of Java.

Start with add()

Append an element to the end or insert it at an index, the first guide in the list.

add() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful