title: Convert map key from collection to double - java
body: <p>I have a <code>Map&lt;String, List&lt;Double&gt;&gt;</code> and from this I want to get a SORTED <code>Map&lt;String, Double&gt;</code> where the keys in both maps are the same but the values in the second map are the averages of the values from the first map and then sorted. I’ve tried: </p>
  
  <pre><code>public class ListComparator implements Comparator&lt;List&lt;Double&gt;&gt; {
      public int compare(List&lt;Double&gt; lhs, List&lt;Double&gt;rhs){
          Double lhs_sum = lhs.stream().mapToDouble(a -&gt; a).sum()/lhs.size();
          Double rhs_sum = rhs.stream().mapToDouble(a -&gt; a).sum()/rhs.size();
          return lhs_sum.compareTo(rhs_sum);
      }
  }
  </code></pre>
  
  <p>And then in main():</p>
  
  <pre><code>ListComparator listComparator = new ListComparator();
  infoMap.entrySet().stream()
                  .sorted(Map.Entry.comparingByValue(listComparator))
                  .limit(15).forEach(System.out::println);
  </code></pre>
  
  <p>But this prints out the key and, it appears, an array of varying number of doubles (should be one double only) that are not sorted. What step am I missing? 
  Thanks </p>