I have Hashmap for example
Map<EmailCategoryModel, List<EmailBlogDetailsModel>> map;
how do I sort Map based on some property of key?
I have Hashmap for example
Map<EmailCategoryModel, List<EmailBlogDetailsModel>> map;
how do I sort Map based on some property of key?
Use TreeMap which is a sorted map and then use comparator or comparable interface. Code:
// Use TreeMap like this
TreeMap<EmailCategoryModel, EmailBlogDetailsModel> map = new TreeMap<>(new ComparatorNew());
// And create comparator somewhat like this
class ComparatorNew implements Comparator<EmailCategoryModel> {
@Override
public int compare(EmailCategoryModel o1, EmailCategoryModel o2) {
// Do sorting based on your model attribute here.
return 0;
}
}