Java LinkedList .removeFirstOccurrence (Object o)

Syntax

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

public boolean removeFirstOccurrence(Object o)

Example

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


//from ww w .j ava  2s.com

import java.util.LinkedList;

public class Main {

   public static void main(String[] args) {

      // create a LinkedList
      LinkedList<String> list = new LinkedList<String>();

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

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

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

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

The code above generates the following result.