title: TreeMap<int[],Double> initialisation and sorting by value
body: <p>I have to make sorted map which key is int[] and value is double. It cant be swapped because double will be duplicated. Moreover, map will be sort by value and last x values will be deleted.</p>
  
  <p>I tried to make </p>
  
  <pre><code>Map&lt;int[],Double&gt; map = new TreeMap&lt;&gt;();;
  int[] i = {0,1,1,0};  
      map.put(i,8.5);  // ERROR HERE Organisms.java:46
      i = new int[]{0,0,0,0};
      map.put(i,30.0);
      System.out.println("sorted" + sortByValue(map));
  </code></pre>
  
  <blockquote>
    <p>Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException:
    [I cannot be cast to java.lang.Comparable     at
    java.util.TreeMap.compare(TreeMap.java:1294)  at
    java.util.TreeMap.put(TreeMap.java:538)   at
    com.pszt_organism.Organisms.test(Organisms.java:46) <strong>&lt;-- MARKED ERROR</strong></p>
  </blockquote>
  
  <p>I found method <code>sortByValue(Map&lt;K, V&gt; map)</code> in this topic: <a href="https://stackoverflow.com/questions/109383/sort-a-mapkey-value-by-values-java">java8 example by Carter Page</a></p>
  
  <p>I suppose that TreeMap has problem with sorting table of int. How to solve that?</p>
  
  <p>EDIT: </p>
  
  <pre><code>private  &lt;K, V extends Comparable&lt;? super V&gt;&gt; Map&lt;K, V&gt; sortByValue(Map&lt;K, V&gt; map) {
          return map.entrySet()
                  .stream()
                  .sorted(Map.Entry.comparingByValue(/*Collections.reverseOrder()*/))
                  .collect(Collectors.toMap(
                          Map.Entry::getKey,
                          Map.Entry::getValue,
                          (e1, e2) -&gt; e1,
                          LinkedHashMap::new
                  ));
      }
  </code></pre>