public
boolean removeFirstOccurrence(Object o)
Removes
the first occurrence of the specified element in this list. Return
true if the list contained the specified element
import java.util.*; class LinkedListRemoveFirstOccurrence{ 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("\nCalling removeFirstOccurrence"); myList.removeFirstOccurrence(10); System.out.println("\nElements in myList are"); System.out.println(myList); } }
Output
Elements in myList are [10, 20, 30, 10] Calling removeFirstOccurrence Elements in myList are [20, 30, 10]
No comments:
Post a Comment