I have th following method. Before returning the result I ned to have the hashmap ordered alphabetically.
how to update my code in order to save in hashmap the string values in alphabetic order? The list I have is alphabetic order, but still after adding it in hashmap the hash begins with e,d,f,g and than with a,b,c,h,i…and so on. WHY?
public Map> getSortedData
{
Map> result= new Hash>();
ArrayList contacts=null;
String currletter=null;
for (T c:objects)
{
if (!c.getLabel().equals(currletter))
{
contats = new ArrayList<T>();
currletter=c.getLabel();
results.put(currletter,contacts);
}
contacts/add(c);
}
how to update my code in order to save in hashmap the string values in alphabetic order? The list I have is alphabetic order, but still after adding it in hashmap the hash begins with e,d,f,g and than with a,b,c,h,i...and so on. WHY?
//??? HERE I WOULD LIKE FIRSTLY TO SORT TH HASHMAP ALFABETICALLY AFTER THE STRING VALUE
return result;
}
Use TreeMap for sorted result