title: Java sort by first index of the array list in a map
body: <p>I know that i can sort a Map using TreeMap but i don't know how to sort by value where the id is the first index of the ArrayList.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>public void sort()
  {
    Map&lt;String, ArrayList&lt;String&gt;&gt; m = new TreeMap&lt;String,ArrayList&lt;String&gt;&gt;();
    String[] name = new String[]{"first name", "second name", "third name"};
    String[] description = new String[]{"first description", "second description", "third description"};
    String[] id = new String[]{"1", "2", "3"};
    m.put(name[0], new ArrayList&lt;String&gt;(Arrays.asList(new String[]{description[0], id[0]})));
    m.put(name[1], new ArrayList&lt;String&gt;(Arrays.asList(new String[]{description[1], id[1]})));
    m.put(name[2], new ArrayList&lt;String&gt;(Arrays.asList(new String[]{description[2], id[2]})));
  }
  </code></pre>
  
  <p>I tried this to sort the Map:</p>
  
  <pre><code>SortedSet&lt;Map.Entry&lt;String, ArrayList&lt;String&gt;&gt;&gt; sortedset = new TreeSet&lt;Map.Entry&lt;String, ArrayList&lt;String&gt;&gt;&gt;(
            new Comparator&lt;Map.Entry&lt;String, ArrayList&lt;String&gt;&gt;&gt;() 
            {
                public int compare(Entry&lt;String, ArrayList&lt;String&gt;&gt; o1, Entry&lt;String, ArrayList&lt;String&gt;&gt; o2)
                {
                  // return Integer.valueOf(o1.getValue()[1]).compareTo(Integer.valueOf(o2.getValue()[1]));
                  return 0;
                } 
            });
  </code></pre>