title: java set Map contents in constructor
body: <p>Is there a way in java to specify the elements in a Map when calling the Map's constructor?</p>
  
  <p>As an example of what I mean, let's say I want a map of the following key/value pairs:</p>
  
  <pre><code>foo: bar
  baz: bat
  </code></pre>
  
  <p>I can add them to an existing Map like this:</p>
  
  <pre><code>Map&lt;String, String&gt; myMap = new HashMap&lt;String, String&gt;();
  myMap.put("foo", "bar");
  myMap.put("baz", "bat");
  </code></pre>
  
  <p>Is there a way to do something like this (with object literals borrowed from javascript as a substitute for what I want):</p>
  
  <pre><code>Map&lt;String, String&gt; myMap = new HashMap&lt;String, String&gt;({"foo": "bar", "baz": "bat"});
  </code></pre>
  
  <p>The reason I ask (in case it makes a difference), is that I want to pass a bunch of HashMaps in-line to a function call, and it would be quite convenient if I didn't have to create variables to hold them and add elements to each one, one at a time.  I'm considering using a JSON parser and writing my Maps as javascript objects to save time, but it would a bit silly if that was really the optimal way to do this.</p>