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.
Programming Tips - Java: How can I initialize a HashMap ?
Date: 2012sep22
Language: Java
Keywords: init
Q. Java: How can I initialize a HashMap ?
A.