title: Converting Hashmap into single string array in java
body: <p>I'm working on a program for class and have been beating my head for days on this. I have to find the number of occurrences in a string. I've been able to get the results into a HashMap.  However, I need to be able to convert it to a single string array so that I can assertTrue and test it.  Here's what I have so far. Any suggestions would be greatly appreciated.  Thanks.</p>
  
  <pre><code>public static void main(String[] args) 
      {
          String input = "xyz 456 123 123 123 123 123 123 xy 98 98 xy xyz abc abc 456 456 456  98 xy"; //String to be tested
          String[] str = input.split(" "); // String put into an array
  
          Map&lt;String, Integer&gt; occurrences = new HashMap&lt;String, Integer&gt;();
          Integer oldValue = 0;
  
          for (String value : str)
          {
              oldValue = occurrences.get(value);
              if (oldValue == null)
              {
                  occurrences.put(value, 1); 
              } else
              {
                  occurrences.put(value, oldValue + 1);
              }
          }
          occurrences.remove("");
  
  }
  </code></pre>
  
  <p>The target string array:</p>
  
  <pre><code>[xy, 3, 123, 6, abc, 2, 456, 4, xyz, 2, 98, 3]
  </code></pre>