我有Hashmap例如
Map<EmailCategoryModel, List<EmailBlogDetailsModel>> map;
如何根据键的某些属性对Map进行排序?
答案 0 :(得分:0)
使用TreeMap,它是一个有序的映射,然后使用比较器或类似的接口。 代码:
// 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;
}
}