Java LinkedList addLast() Method
Example
Add an item to the end of the list:
import java.util.LinkedList;
public class Main {
public static void main(String[] args) {
LinkedList<String> cars = new LinkedList<String>();
cars.add("Volvo");
cars.add("BMW");
cars.add("Ford");
// Use addLast() to add the item to the end
cars.addLast("Mazda");
System.out.println(cars);
}
}
Definition and Usage
The addLast()
method adds an item to the end of the list.
Tip: Use the addFirst()
method to add an item to the beginning of the list.
Syntax
public void addLast(T item)
T
refers to the data type of items in the list.
Parameter Values
Parameter | Description |
---|---|
item | Required. The item to be added to the end of the list |
Related Pages
❮ LinkedList Methods