Java LinkedList.contains(Object o)
Syntax
LinkedList.contains(Object o) has the following syntax.
public boolean contains(Object o)
Example
In the following code shows how to use LinkedList.contains(Object o) method.
// w w w.java 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);
// check if the list contains "Coffee"
System.out.println("List contains 'Coffee':" + list.contains("Coffee"));
// check if the list contains "10"
System.out.println("List contains '10':" + list.contains("10"));
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.util »
Java Tutorial »
java.util »