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 281 views
1 answer 232 views
1 answer 240 views
1 answer 283 views
1 answer 320 views
...