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

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

python - Error: Unresolved reference 'selenium' What is the reason? -

asp.net ajax - Jquery scroll to element just goes to top of page -