Adding elements to a set on creation
Since Java 7, to instantiate a single-element, immutable Set, you can use: Collections.singleton(thing); Returns an immutable set containing only the specified object. The returned set is serializable. — Javadoc reference: Collections.singleton(T) In Java 8 you can instantiate a Set containing any number of your objects with the following, which is an adaptation of this answer: … Read more