Related Examples
 

Java LinkedList removeFirstOccurrence Example

LinkedList class removeFirstOccurrence method example. This example shows you how to use removeFirstOccurrence method.


LinkedList class removeFirstOccurrence method example.public boolean removeFirstOccurrence(Object o) Removes the first occurrence of the specified element in this list (when traversing the list from head to tail). If the list does not contain the element, it is unchanged.

Here is the code

/**
 * @ # RemoveFirstOccurrence.java
 * A class repersenting use to removeFirstOccurrence method of LinkedList class in java.util package
 * version 15 May 2008
 * author Rose India 
 */
import java.util.*;

public class RemoveFirstOccurrence {

    public static void main(String args[]) {
        LinkedList list = new LinkedList();
        int i = 11;
        String str = "Rose";

        //Add the specified element to the end of this list.
        list.add(i);
        list.add(str);
        list.add("India");

        System.out.println("Remove first element "+list.removeFirstOccurrence("Rose"));
        System.out.println("list = " + list);
    }
}

Output
Remove first element true
list = [11, India]

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US