Bijan
0
Q:

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");
      // check if element exists
      boolean bool = hs.contains("world");
      System.out.println("Is element 'world' exists: " + bool);
   }
}
1
public class HashSetDemo {
   public static void main(String args[]) {
      
      // create hash set
      HashSet <String> newset = new HashSet <String>();

      // populate hash set
      newset.add("Learning"); 
      newset.add("Easy");
      newset.add("Simply");  

      // check the existence of element
      boolean exist = newset.contains("Simply");

      System.out.println("Is the element 'Simply' exists: "+ exist);
   }    
}
0

New to Communities?

Join the community