set contains in java

Solutions on MaxInterview for set contains in java by the best coders in the world

showing results for - "set contains in java"
Hannah
06 Jan 2017
1public class HashSetDemo {
2   public static void main(String args[]) {
3      
4      // create hash set
5      HashSet <String> newset = new HashSet <String>();
6
7      // populate hash set
8      newset.add("Learning"); 
9      newset.add("Easy");
10      newset.add("Simply");  
11
12      // check the existence of element
13      boolean exist = newset.contains("Simply");
14
15      System.out.println("Is the element 'Simply' exists: "+ exist);
16   }    
17}