initialize a Hashset with objects in java code example Example: initialize hashset java Set<String> h = new HashSet<>(Arrays.asList("a", "b"));