8:22 pm - Wednesday October 18, 2017

LinkedList Example Program for removeFirstOccurrence(Object o)

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044
/**
*LinkedList Example Program for removeFirstOccurrence(Object o)
* @author   candidjava.com
* @description: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.
*/
import java.util.*;

public class Line1 {
public static void main(String args[]) {
LinkedList s = new LinkedList();// create object for linkedlist
s.add(1);
s.add(3);// add elements.
s.add(4);
s.add(3);
System.out.println("Before removing" + s);
s.removeFirstOccurrence(3);// this function used for remove first occur
// element in the list.
System.out.println("after removing" + s);
}
}
<span style="color: #3366ff;">Output:</span>
Before removing[1, 3, 4, 3]
after removing[1, 4, 3]


Output:

Before removing[1, 3, 4, 3]
after removing[1, 4, 3]

BACK

Filed in: Z-A All Java Codes

Comments are closed.