How to sort an ArrayList?

后端 未结 20 2110
有刺的猬
有刺的猬 2020-11-22 06:19

I have a List of doubles in java and I want to sort ArrayList in descending order.

Input ArrayList is as below:

List testList = new Arr         


        
20条回答
  •  抹茶落季
    2020-11-22 06:35

    If you have to sort object based on its id in the ArrayList , then use java8 stream.

     List personList = new ArrayList<>();
    
        List personListSorted =
                    personList.stream()
                      .sorted(Comparator.comparing(Person::getPersonId))
                      .collect(Collectors.toList());
    

提交回复
热议问题