I need to initialize a constant HashMap and would like to do it in one line statement. Avoiding sth like this:
hashMap.put(\"One\", new Integer(1)); // add
Here's a simple class that will accomplish what you want
import java.util.HashMap; public class QuickHash extends HashMap { public QuickHash(String...KeyValuePairs) { super(KeyValuePairs.length/2); for(int i=0;i
And then to use it
Map Foo=QuickHash( "a", "1", "b", "2" );
This yields {a:1, b:2}
{a:1, b:2}