collections - singletons

 

Collections provides three methods which accept an Object and return an immutable single-Object List, Set, or Map.

 

■ Note the default naming for the Set:

 

singletonList(Obj)                                                                                returns a List     i.e.

List ls = new ArrayList(Collections.singletonList("abc"));

 

Collections.singletonMap("1", "A");                                                  returns a Map     

 

HashSet hs = new HashSet(Collections.singleton("xyz"));           returns a Set