Java LinkedList.removeLast()
Syntax
LinkedList.removeLast() has the following syntax.
public E removeLast()
Example
In the following code shows how to use LinkedList.removeLast() method.
//from w ww.ja v a2s. co m
import java.util.LinkedList;
public class Main {
public static void main(String[] args) {
LinkedList<String> list = new LinkedList<String>();
// add some elements
list.add("Hello");
list.add("from");
list.add("java2s.com");
System.out.println("LinkedList:" + list);
// remove the last element
System.out.println("Last element:" + list.removeLast());
// print the list
System.out.println("LinkedList:" + list);
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.util »
Java Tutorial »
java.util »