Programming Tips - How can I initialize a HashMap ?

Date: 2012sep22 Language: Java Keywords: init Q. How can I initialize a HashMap ? A.
HashMap<String,String> fruitToColor = new HashMap<String, String>() {{ put("apple", "red"); put("orange", "orange"); put("banana", "yellow"); }}; // Notice the double brace brackets.
Some people don't like the double brace brackets because it creates an anonymous inner class. But I like it because its compact.