hashset 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: hashset contains java
HashSet<Integer> set = new HashSet<Integer>();
set.contains(110)
Example 3: hashset in java
Let’s see java hashset example.
import java.util.HashSet;
public class HashSetExample
{
public static void main(String[] args)
{
HashSet<String> hs = new HashSet<>();
hs.add("Banana");
hs.add("Orange");
hs.add("Apple");
hs.add("Pineapple");
hs.add("Mango");
System.out.println(hs);
}
}