Sorting objects within a Set by a String value that all objects contain

后端 未结 7 922
北荒
北荒 2021-01-01 01:30

Ok this is a tricky one. I have a list of Sets. I would like to sort the objects in the Sets in an order.

Imagine each set as repressenting a class in a school. Each

7条回答
  •  迷失自我
    2021-01-01 02:28

    With Java 8 you can sort the Set of persons and generate List of persons which are sorted as follows.

    List personList = personSet.stream().sorted((e1, e2) -> 
    e1.getName().compareTo(e2.getName())).collect(Collectors.toList());
    

提交回复
热议问题