Java LinkedList.indexOf(Object o)
Syntax
LinkedList.indexOf(Object o) has the following syntax.
public int indexOf(Object o)
Example
In the following code shows how to use LinkedList.indexOf(Object o) method.
/*from ww w .j av a 2 s . c o m*/
import java.util.LinkedList;
public class Main {
public static void main(String[] args) {
// create a LinkedList
LinkedList<String> list = new LinkedList<String>();
// add some elements
list.add("Hello");
list.add("from java2s.com");
list.add("10");
// print the list
System.out.println("LinkedList:" + list);
// get the index for "Chocolate"
System.out.println("Index for Chocolate:" + list.indexOf("Hello"));
// get the index for "Coffee"
System.out.println("Index for Coffee:" + list.indexOf("Coffee"));
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.util »
Java Tutorial »
java.util »