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
Post a Comment