I don't understand why you would need java Collections singletonMap? Is it useful in multithreaded applications?
Basically, it allows you to do this:
callAPIThatTakesAMap(Collections.singletonMap(key, value));
rather than this:
Map<KeyType, ValueType> m = new HashMap<KeyType, ValueType>();
m.put(key, value);
callAPIThatTakesAMap(m);
which is much nicer when you only have a single key/value pair. This situation probably does not arise very often, but singleton()
and singletonList()
can quite frequently be useful.