I found a blog sometime back at
http://nileshbansal.blogspot.com/2009/04/initializing-java-maps-inline.html
It shows how to inline initialize a Java map, like so:
Map
put("Harry", "Potter");
put("Ron", "Weasley");
put("Hermione", "Granger");
}};
I find myself forgetting the exact syntax if I haven't used in awhile so I thought I would blog it :-)
An alternate way is using Google collections:
Map<String, String> map = ImmutableMap.of( "x", "y" );
Java Maps Inline Initialization
Tim Harsch, Tuesday, September 15, 2009
Subscribe to:
Post Comments (Atom)
Comments :
Post a Comment