In Java, How do you quicksort an ArrayList of objects in which the sorting field is multiple layers deep?

前端 未结 4 877
终归单人心
终归单人心 2021-02-10 13:51

Basically, I have a Container class called \"Employees\" which has in it an ArrayList. This ArrayList contains \"Employee\" objects, which in turn contain \"EmployeeData\" objec

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-10 14:53

    Define Employee implements Comparable.

    In the compareTo method, dig into the layers and compare the strings you need. Then you can use Collections.sort(), or you can store the data in a SortedSet, which is naturally ordered.

提交回复
热议问题