Java LinkedList removeLastOccurrence Example
LinkedList class removeLastOccurrence method example. This example shows you how to use removeLastOccurrence method.
LinkedList class removeLastOccurrence method example. public boolean removeLastOccurrence(Object o) Removes the last 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
/**
* @ # RemoveLastOccurrence.java
* A class repersenting use to removeLastOccurrence method of LinkedList class in java.util package
* version 15 May 2008
* author Rose India
*/
import java.util.*;
public class RemoveLastOccurrence {
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 element " + list.removeFirstOccurrence("India"));
System.out.println("list = " + list);
}
} |
Output
Remove element true
list = [11, Rose] |
|