The Collections
class provides for the ability to
create single element sets fairly easily. Instead of having to
create the Set
and fill it in in separate steps, you can do
it all at once. The resulting Set
is immutable.
Set set = Collection.singleton("Hello");
The Java 2 SDK, Standard Edition, version 1.3 adds the ability
to create singleton lists and maps, too:
List singletonList(Object element)
Map singletonMap(Object key, Object value)