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.
Here is the code:
public void sort()
{
Map<String, ArrayList<String>> m = new TreeMap<String,ArrayList<String>>();
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<String>(Arrays.asList(new String[]{description[0], id[0]})));
m.put(name[1], new ArrayList<String>(Arrays.asList(new String[]{description[1], id[1]})));
m.put(name[2], new ArrayList<String>(Arrays.asList(new String[]{description[2], id[2]})));
}
I tried this to sort the Map:
SortedSet<Map.Entry<String, ArrayList<String>>> sortedset = new TreeSet<Map.Entry<String, ArrayList<String>>>(
new Comparator<Map.Entry<String, ArrayList<String>>>()
{
public int compare(Entry<String, ArrayList<String>> o1, Entry<String, ArrayList<String>> o2)
{
// return Integer.valueOf(o1.getValue()[1]).compareTo(Integer.valueOf(o2.getValue()[1]));
return 0;
}
});