How to sort an ArrayList?

后端 未结 20 2135
有刺的猬
有刺的猬 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:34

    In JAVA 8 its much easy now.

    List alphaNumbers = Arrays.asList("one", "two", "three", "four");
    List alphaNumbersUpperCase = alphaNumbers.stream()
        .map(String::toUpperCase)
        .sorted()
        .collect(Collectors.toList());
    System.out.println(alphaNumbersUpperCase); // [FOUR, ONE, THREE, TWO]
    

    -- For reverse use this

    .sorted(Comparator.reverseOrder())
    

提交回复
热议问题