How to sort ArrayList in a reverse order with Java

1 Answer

0 votes
import java.util.ArrayList;
import java.util.Collections;

public class MyClass {
    public static void main(String args[]) {
        ArrayList<String> al = new ArrayList<String>() {{
            add("java");
            add("c#");
            add("php");
            add("c");
        }};
        
        Collections.sort(al, Collections.reverseOrder());
        
        System.out.println(al);
    }
}



/*
run:

[php, java, c#, c]

*/

 



answered Apr 4, 2021 by avibootz

Related questions

1 answer 193 views
1 answer 149 views
1 answer 150 views
1 answer 177 views
1 answer 213 views
...