java - How to sort a hashmap whose keys are models? -
i have hashmap example
map<emailcategorymodel, list<emailblogdetailsmodel>> map;
how sort map based on property of key?
use treemap sorted map , use comparator or comparable interface. code:
// use treemap treemap<emailcategorymodel, emailblogdetailsmodel> map = new treemap<>(new comparatornew()); // , create comparator class comparatornew implements comparator<emailcategorymodel> { @override public int compare(emailcategorymodel o1, emailcategorymodel o2) { // sorting based on model attribute here. return 0; } }
Comments
Post a Comment