LinkedList.removeLast() has the following syntax.
public E removeLast()
In the following code shows how to use LinkedList.removeLast() method.
//w w w.j a v a 2s .c o 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.