1:58 am - Saturday December 15, 2018

LinkedList Example Program for indexOf(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
/**
Author :candidjava.com
Description:  Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.
*/
import java.io.IOException;
import java.util.*;
public class LinkedListIndexOf
 {
public static void main(String args[])
{
boolean a;
int b=60,c=20,d=30,e,f=60;
LinkedList l=new LinkedList();
a=l.add(b);
a=l.add(c);
a=l.add(d);
e=l.indexOf(f);//returns the position of the element in the list
System.out.println("position of the given element in the list is " +e);
}
}

Output:

position of the given element in the list is
0

Filed in: Core Java Tutorial

Comments are closed.