title: Reduce a Map where the keys are values in some entries
body: <p>I am trying to make a new Map from a another Map where some of the values are keys in other entries.</p>
  
  <p>Example:</p>
  
  <pre><code>HashMap&lt;String,String&gt; testMap = new HashMap&lt;&gt;();
  testMap.put("a","b");
  testMap.put("b","d");
  testMap.put("d","e");
  testMap.put("e","f");
  testMap.put("k","r");
  </code></pre>
  
  <p>I need as result a new Map with this format:</p>
  
  <p><code>a-&gt;f</code><br>
  <code>b-&gt;f</code><br>
  <code>d-&gt;f</code><br>
  <code>e-&gt;f</code><br>
  <code>k-&gt;r</code></p>
  
  <pre><code>producedMap.put("a","f");
  producedMap.put("b","f");
  producedMap.put("d","f");
  producedMap.put("e","f");
  producedMap.put("k","r");
  </code></pre>
  
  <p>My code is that, but seems not give the true result.</p>
  
  <pre><code>    public HashMap&lt;String,String&gt; getMatched(HashMap&lt;String,String&gt; correpondanceMap){
  
      Collection&lt;String&gt; correpondanceKeys = correpondanceMap.keySet();
      HashMap&lt;String,String&gt; newCorrepondanceMap= new HashMap&lt;&gt;();
      correpondanceMap.entrySet().forEach(entry-&gt;{
          if (correpondanceKeys.contains(entry.getValue())){
              String newValue = entry.getValue();
              String keyOfnewValue = correpondanceMap
                      .entrySet()
                      .stream()
                      .filter(entriii -&gt; newValue.equals(entry.getValue()))
                      .map(Map.Entry::getKey).limit(1).collect(Collectors.joining());
  
  
              newCorrepondanceMap.put(keyOfnewValue,correpondanceMap.get(newValue));
          }
          else
          {
              newCorrepondanceMap.put(entry.getKey(),entry.getValue());
          }
      });
  
      newCorrepondanceMap.entrySet().forEach(entry-&gt; System.out.println(entry.getKey() +"  -- &gt; " +entry.getValue()));
  
      return newCorrepondanceMap;
  }
  </code></pre>