title: Java Stream Api - good ways to operate on Map<String, Double>?
body: <p>I want to do some calculations with weighted averages. There are two maps </p>
  
  <pre><code>Map&lt;String, Double&gt; weightedVector;
  Map&lt;String, Double&gt; otherVector;
  </code></pre>
  
  <p>The pseudo algorithm is like this</p>
  
  <pre><code>foreach entry in weightedVector:
    get same entry from otherVector 
    - if it exists then multiply weights and add new entry to another map
    - otherwise do nothing
  </code></pre>
  
  <p>I want to take advantage of the Stream API and came up with this</p>
  
  <pre><code>Stream&lt;Double&gt; map = weightedVector.entrySet().parallelStream()
  .map(entry -&gt; {
      Double t = otherVector.get(entry.getKey());
      Double v = entry.getValue();
      return (t != null &amp;&amp; v != null) 
              ? t * v 
              : 0.0;
  });
  </code></pre>
  
  <p>One question I ask myself whether it is good practice to use the old-style in order to access <code>otherVector</code> like in the snippet above.</p>
  
  <p>The main problem for me is that I have two input maps and want to get an output map of the same type but the code above gets me a <code>Stream</code> of <code>Double</code> from the calculation.</p>
  
  <p>Am I better off using <code>stream().collect(..)</code>, then how?</p>
  
  <p>Is it maybe better to not use the <code>HashMap</code> but rather create a container object containing the key-value pair and use that instead?</p>