set.contains in java code example
Example 1: HashSet contains(Object o) method in java
import java.util.HashSet;
public class HashSetContainsObjectMethodExample
{
public static void main(String[] args)
{
HashSet<String> hs = new HashSet<String>();
hs.add("hello");
hs.add("world");
hs.add("java");
boolean bool = hs.contains("world");
System.out.println("Is element 'world' exists: " + bool);
}
}
Example 2: set contains in java
public class HashSetDemo {
public static void main(String args[]) {
HashSet <String> newset = new HashSet <String>();
newset.add("Learning");
newset.add("Easy");
newset.add("Simply");
boolean exist = newset.contains("Simply");
System.out.println("Is the element 'Simply' exists: "+ exist);
}
}