HashSet<Integer> set = new HashSet<>(); set.add(1); set.add(2); if(set.contains(1)){ print("hashset contains 1"); } else{ print("hashset doesn't contain 1"); } //output hashset contains 1