Grouping elements of a list into sublists (maybe by using guava)

后端 未结 4 2011
南笙
南笙 2020-12-13 00:44

I want to group elements of a list. I\'m currently doing it this way:

public static  List> group(final List list, fina         


        
4条回答
  •  悲&欢浪女
    2020-12-13 01:03

    The easiest and simplest way would be using: Lamdaj grouping feature

    The above example can be re-written:

    List badGuys = Arrays.asList("Inky", "Blinky", "Pinky", "Pinky", "Clyde");
    Group group = group(badGuys, by(on(String.class).length)));
    System.out.println(group.keySet());
    

提交回复
热议问题