Combining two different strings in a map
<p>I've been trying out the new section on codingbat, map1 &amp; 2. I've finished map1, and I'm halfway through map2 but I'm just stuck on this one problem. I can't seem to figure out how to combine two strings.</p>

<blockquote>
  <p>Given an array of non-empty strings, return a <code>Map&lt;String, String&gt;</code>
  with a key for every different first character seen, with the value of
  all the strings starting with that character appended together in the
  order they appear in the array.</p>
</blockquote>

<p>Examples:</p>

<pre><code>firstChar(["salt", "tea", "soda", "toast"]) → {"t": "teatoast", "s": "saltsoda"}
firstChar(["aa", "bb", "cc", "aAA", "cCC", "d"]) → {"d": "d", "b": "bb", "c": "cccCC", "a": "aaaAA"}
firstChar([]) → {}
</code></pre>

<p>Here's my code:</p>

<pre><code>public Map&lt;String, String&gt; firstChar(String[] strings)                       
{             
  Map&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();       
  String x = "";         
   for ( String s: strings )    
     {
      if ( s.substring(0,1) == s.substring(0,1))   
       x += s;   
         map.put(s.substring(0,1), x);        
     }     
  return map;   
}
</code></pre>

<p>I only get <code>{"d": "d", "b": "", "c": "", "a": ""}</code></p>

<p>I've also tried <code>s.substring(0, 1, map.get(s) + map.get(s))</code> which only returns <code>null</code>. If anyone could explain this to me it would be greatly appreciated!</p>

<p>Thank you !</p>