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

后端 未结 7 953
北荒
北荒 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<Person> personList = personSet.stream().sorted((e1, e2) -> 
    e1.getName().compareTo(e2.getName())).collect(Collectors.toList());
    
    0 讨论(0)
提交回复
热议问题