So i have HashMap which i convert it to Object so i can sort it by value, now by default i sort it as descending, but i would need other option too to sort it as ascending.
I used simple array sort:
HashMap<String, Integer> prefMap = getMyList();
Object[] a = prefMap.entrySet().toArray();
Arrays.sort(a, new Comparator() {
public int compare(Object o1, Object o2) {
return ((Map.Entry<String, Integer>) o2).getValue()
.compareTo(((Map.Entry<String, Integer>) o1).getValue());0
}
});
The upper code works for descending, should i just compare with if/else if i want to sort them as ascending?