title: Can I declare and initialize a map in java with a literal?
body: <p>Is it possible to declare and initialize a <code>Hashtable</code> or <code>Map</code>, so we don't have to declare and initialize on two different steps?</p>
  <pre class="lang-java prettyprint-override"><code>// declare first
  Hashtable&lt;String, Integer&gt; numbers = new Hashtable&lt;String, Integer&gt;(3);
  
  // then initialize
  numbers.put(&quot;one&quot;, 1);
  numbers.put(&quot;two&quot;, 2);
  numbers.put(&quot;three&quot;, 3);
  </code></pre>
  <p>In ruby and javascript, for example, there are literals to define those:</p>
  <pre class="lang-rb prettyprint-override"><code>numbers = {
    one: 1,
    two: 2,
    three: 3,
  }
  </code></pre>