Is there some way of initializing a Java HashMap like this?:
Map test =
new HashMap{\"test\":\"test\",\"test\
This is one way.
Map h = new HashMap() {{
put("a","b");
}};
However, you should be careful and make sure that you understand the above code (it creates a new class that inherits from HashMap). Therefore, you should read more here: http://www.c2.com/cgi/wiki?DoubleBraceInitialization , or simply use Guava:
Map left = ImmutableMap.of("a", 1, "b", 2, "c", 3);
ImmutableMap.of works for up to 5 entries. Otherwise, use the builder: source.