Possible Duplicate:
builder for HashMap
Are there any utility class which allows to create a Map from a number of key-value pairs in a convenient and readable manner?
I thought that guava
should have contain something but I couldn't find anything with necessary functionality.
What I want is something like this:
MapBuilder.newHashMap()
.with("key1", 10)
.with("key2", 20)
.with("key3", 30)
.build();
P.S. I also know about double-brace approach (new HashMap<>() {{ put(..); put(..); }}
) but I don't find it either readable or convenient.