Java LinkedList .removeLastOccurrence (Object o)

Syntax

LinkedList.removeLastOccurrence(Object o) has the following syntax.

public boolean removeLastOccurrence(Object o)

Example

In the following code shows how to use LinkedList.removeLastOccurrence(Object o) method.


import java.util.LinkedList;
//from  w w w .ja v a 2 s  .c  o m
public class Main {

   public static void main(String[] args) {

      LinkedList<String> list = new LinkedList<String>();

      // add some elements
      list.add("Hello");
      list.add("tutorial");
      list.add("from java2s.com");
      list.add("Hello");

      // print the list
      System.out.println("LinkedList:" + list);

      // remove the last "Hello"
      boolean found = list.removeLastOccurrence("Hello");
      System.out.println("Element found:" + found);

      // print the list
      System.out.println("LinkedList:" + list);
   }
}

The code above generates the following result.