Java LinkedList contains Example
LinkedList class contains method example. This example shows you how to use contains method.
LinkedList class contains method example.public boolean contains(Object o) Returns true if this list contains the specified element.
Here is the code
/**
* @ # Contains.java
* A class repersenting use to contains method of LinkedList class in java.util package
* version 15 May 2008
* author Rose India
*/
import java.util.*;
public class Contains {
public static void main(String args[]) {
List list = new LinkedList();
int i = 0;
String str = "Rose";
//Add the specified element to the end of this list.
list.add(i);
list.add(str);
list.add("India");
System.out.println("list = " + list);
//Returns true if this list contains the specified element.
System.out.println("LinkedList contains India "+list.contains("India"));
}
} |
Output
list = [0, Rose, India]
LinkedList contains India true |
|