L
laredotornado
Hi,
Does anyone know how to sort a map.entrySet by the value? Each entry
is an Integer mapped to a String, but I wish to have the whole thing
sorted alphabetically by the strings. Any ideas how I can do this?
Below is the function that ultimately serves up the map.entrySet.
(The Map[] object is a list returned from a database).
Thanks, - Dave
@ModelAttribute("promoEntryTypes")
public Set<Map.Entry<String, String>>
populatePromoEntryTypes(@ModelAttribute("appInterface")
JspAppInterfaceAdmin appInterface) {
final Map<String, String> map = new TreeMap<String, String>();
try {
if (appInterface != null) {
Map[] promoEntryTypes = appInterface.getUserPromotionTypes();
for (int i=0; i<promoEntryTypes.length; i++) {
map.put(((Integer) promoEntryTypes.get("id")).toString(),
(String) promoEntryTypes.get("promotion_name"));
} // for
} // if
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return map.entrySet();
}
Does anyone know how to sort a map.entrySet by the value? Each entry
is an Integer mapped to a String, but I wish to have the whole thing
sorted alphabetically by the strings. Any ideas how I can do this?
Below is the function that ultimately serves up the map.entrySet.
(The Map[] object is a list returned from a database).
Thanks, - Dave
@ModelAttribute("promoEntryTypes")
public Set<Map.Entry<String, String>>
populatePromoEntryTypes(@ModelAttribute("appInterface")
JspAppInterfaceAdmin appInterface) {
final Map<String, String> map = new TreeMap<String, String>();
try {
if (appInterface != null) {
Map[] promoEntryTypes = appInterface.getUserPromotionTypes();
for (int i=0; i<promoEntryTypes.length; i++) {
map.put(((Integer) promoEntryTypes.get("id")).toString(),
(String) promoEntryTypes.get("promotion_name"));
} // for
} // if
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return map.entrySet();
}