java - Performance of Sorting a HashMap by Value vs Using TreeMap or LinkedHashMap -


i'm sorting hashmap value , wondering whether performance better if better sort using treemap instead.

i know hashmap's have insertion , sorting complexity of o(1) time , tree sort in java take log(n) (i believe), i'm wondering cost of sorting hashmap is.

i'm sorting with:

 public static hashmap sortbyvalue(map unsortmap) {     list list = new linkedlist(unsortmap.entryset());      collections.sort(list, new comparator() {         public int compare(object o1, object o2) {             return ((comparable) ((map.entry) (o2)).getvalue())                     .compareto(((map.entry) (o1)).getvalue());         }     });      hashmap sortedmap = new linkedhashmap();     (iterator = list.iterator(); it.hasnext();) {         map.entry entry = (map.entry) it.next();         sortedmap.put(entry.getkey(), entry.getvalue());     }     return sortedmap; } 

which method best use , why?

edit: meant searching, not sorting complexity.


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -