You create a HashSet by specifying the element type, then use .add() and .contains() to manage it:
import java.util.HashSet;
HashSet<String> seen = new HashSet<>();
seen.add("apple");
seen.add("banana");
seen.add("apple"); // duplicate, ignored
System.out.println(seen.contains("apple")); // true
System.out.println(seen.contains("cherry")); // false
System.out.println(seen.size()); // 2
The .add() method returns true if the element was new and false if it was already present. The set still holds only elements after the .add() calls because duplicates are silently ignored.