title: Building a map from key-values pairs in Java
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/7345241/builder-for-hashmap">builder for HashMap</a>  </p>
  </blockquote>
  
  
  
  <p>Are there any utility class which allows to create a Map from a number of key-value pairs in a convenient and readable manner?</p>
  
  <p>I thought that <code>guava</code> should have contain something but I couldn't find anything with necessary functionality.</p>
  
  <p>What I want is something like this:</p>
  
  <pre><code>MapBuilder.newHashMap()
    .with("key1", 10)
    .with("key2", 20)
    .with("key3", 30)
    .build();
  </code></pre>
  
  <p>P.S. I also know about double-brace approach (<code>new HashMap&lt;&gt;() {{ put(..); put(..); }}</code>) but I don't find it either readable or convenient.</p>