For flexibility, you can use Java Streams to collect values into a set.
Set<String> h = Stream.of("a", "b", "c").collect(Collectors.toSet());
Why This Works:
Uses Stream.of() to create a stream of elements and then collects them into a set.
Allows transformation of data before collecting.
Downside:
Slightly less readable for simple cases.
Less efficient for small sets due to stream overhead.
Usage Example:
Set<Double> uniqueSquares = Stream.of(2.0, 3.0, 4.0)
.map(x -> x * x)
.collect(Collectors.toSet());