title: How to replace HashMap with LinkedhashMap with streams?
body: <p>Could you please help me to sort my <code>Map</code>?</p>
  
  <p>I have the following structure and I want to assemble apps under customers in a <code>LinkedHashMap</code> in a reversed order by value.</p>
  
  <pre><code>[{
    "CUSTOMER_1": {
      "APP_1": "1"
    },
    "CUSTOMER_2": {
      "APP_1": "2",
      "APP_3": "7",
      "APP_2": "3"
    }
  }]
  </code></pre>
  
  <p>I already have a lambda that assembles the map:</p>
  
  <pre><code> final Map&lt;String, Map&lt;String, Long&gt;&gt; organizationApps = taskHandles.stream().map(this::mapPayload)
              .flatMap(e -&gt; e.entrySet().stream())
              .collect(groupingBy(Map.Entry::getKey, of(HashMap::new,
                      (r, t) -&gt; t.getValue().forEach((k, v) -&gt; r.merge(k, v, Long::sum)),
                      (r1, r2) -&gt; {
                          r2.forEach((v1, v2) -&gt; r1.merge(v1, v2, Long::sum));
                          return r1;
                      }))
              );
  </code></pre>
  
  <p>What I need now is to replace <code>organizationApps</code> values that are represented by <code>HashMap</code> with a <code>LinkedHashMap</code> and put the values into <code>LinkedHashMap</code> in a proper order.</p>
  
  <p>How can I do it in lambda?</p>
  
  <p>UPD:</p>
  
  <p>I can achieve the necessary output with the following piece of code:</p>
  
  <pre><code>    final Map&lt;String, Map&lt;String, Long&gt;&gt; organizationApps = taskHandles.stream().map(this::mapPayload)
              .flatMap(e -&gt; e.entrySet().stream())
              .collect(groupingBy(Map.Entry::getKey, of(HashMap::new,
                      (r, t) -&gt; t.getValue().forEach((k, v) -&gt; r.merge(k, v, Long::sum)),
                      (r1, r2) -&gt; {
                          r2.forEach((v1, v2) -&gt; r1.merge(v1, v2, Long::sum));
                          return r1;
                      }))
              );
  
      organizationApps.forEach((key, value) -&gt; {
          final Map&lt;String, Long&gt; sorted = value.entrySet()
                  .stream()
                  .sorted(reverseOrder(Map.Entry.comparingByValue()))
                  .collect(toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -&gt; e2,
                          LinkedHashMap::new));
          organizationApps.put(key, sorted);
      });
  </code></pre>
  
  <p>How can I do it in one lambda?</p>