📌  相关文章
📜  如何在java代码示例中对列表进行排序

📅  最后修改于: 2022-03-11 14:52:18.064000             🧑  作者: Mango

代码示例2
List elements = new ArrayList<>();
// The list of strings will be sorted lexicographically
elements.sort();
// You can also implement a custom comparator
Comparator comp = new Comparator(){
   @Override
   public int compare(final String s1,String s2) {
     //TODO return 1 if rhs should be before lhs 
     //     return -1 if lhs should be before rhs
     //     return 0 otherwise (meaning the order stays the same)
     }
 };
elements.sort(comp);