group by - Kotlin sortBy on TreeMap -


what kotlin way of accomplisg this:

public static treemap<integer, arraylist<homeitem>> gethomeitemlistsseparatedbypageid(list<homeitem> homeitemslist) {          if (homeitemslist.size() == 0) {             return new treemap<>();         }          treemap<integer, arraylist<homeitem>> map = new treemap<>();          (homeitem hl : homeitemslist) {             if (map.get(hl.getvisiblepageid()) == null) {                 map.put(hl.getvisiblepageid(), new arraylist<>());             }             map.get(hl.getvisiblepageid()).add(hl);         }          return map;     } 

i have tried apply groupby on args list returns hashmap.

edit: basically, original list queried, , grouped visiblepageid, , added treemap key id , value items id

you can use groupbyto method , pass treemap instance first argument.

fun gethomeitemlistsseparatedbypageid(homeitems: list<homeitem>) =     homeitems.groupbyto(treemap()) { it.visiblepageid } 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -