Sunday, 25 May 2014

LinkedList : removeLastOccurrence (Object o) : Removes the Last Occurrence of given element

public boolean removeLastOccurrence(Object o)
Removes the last occurrence of the specified element in this list. Return true if the list contained the specified element

import java.util.*;

class LinkedListRemoveLastOccurrence{
 public static void main(String args[]){
  LinkedList<Integer> myList;
  myList = new LinkedList<> ();
  
  /* Add Elements to myList */
  myList.add(10);
  myList.add(20);
  myList.add(30);
  myList.add(10);
  
  System.out.println("Elements in myList are");
  System.out.println(myList);
  
  System.out.println("\nRemoving Last Occurrence of 10");
  myList.removeLastOccurrence(10);
  
  System.out.println("\nElements in myList are");
  System.out.println(myList);
 }
}

Output
Elements in myList are
[10, 20, 30, 10]

Removing Last Occurrence of 10

Elements in myList are
[10, 20, 30]

Prevoius                                                 Next                                                 Home

No comments:

Post a Comment