I have an ArrayList.
Each element is a HashMap lookup for my values.
1 of the values is numeric.
I'm using Collections.sort() for alpha sorting. But the numbers are getting alpha sorted, instead of numeric sorted.
protected ArrayList<HashMap<String, String>> myAccountList;
String Name = myAccountList.get(i).get("accountName");
Double balance = Double.valueOf(myAccountList.get("accountBalance")); //is a number stored as a string
So I have the sort working on accountName just fine.
Collections.sort(myAccountList, new Comparator(){
public int compare(Object o1, Object o2) {
HashMap<String,String> old1 = (HashMap<String, String>) o1;
HashMap<String,String> old2 = (HashMap<String, String>) o2;
return old1.get("accountName").compareToIgnoreCase(old2.get("accountName"));
}
});
How would I sort the field accountBalance as a number? I doubt it matters, but I'm programming an Android app.
Doubleinstead? For example,HashMap<String, Double>HashMap<String, Object>.HashMapat all - see my answer.