Is there a more streamlined way to do the following?
Map map = new HashMap();
map.put(\"a\", \"apple\");
map.put(
There's always double-brace initialization:
Map map = new HashMap(){{
put("a", "apple"); put("b", "bear"); put("c", "cat");}};
There are problems with this approach. It returns an anonymous inner class extending HashMap, not a HashMap. If you need to serialize the map then know that serialization of inner classes is discouraged.