Effective method to sort list in Java I am a beginner in Java and am learning collections. I have written the following code to sort the elements in lists.

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

class descendingOrder implements Comparator&lt;Integer&gt;{
    @Override
    public int compare(Integer numberOne, Integer numberTwo) {
        return -numberOne.compareTo(numberTwo); 
    }
}

public class SortsTests {

    public static void main(String[] args) {
        List&lt;Integer&gt; listOne = new ArrayList&lt;&gt;();
        listOne.add(1);
        listOne.add(5);
        listOne.add(10);
        listOne.add(6);
        System.out.println(listOne);
        Collections.sort(listOne, new descendingOrder());
        System.out.println(listOne);
    }
}


Is this the most effective way to sort the lists or are there any better methods?
There is already a reverse order Comparator built-in to Java. You could also use Arrays.asList(T...); like,

List&lt;Integer&gt; listOne = Arrays.asList((Integer) 1, 5, 10, 6);
System.out.println(listOne);
Collections.sort(listOne, Comparator.reverseOrder());
System.out.println(listOne);


And if you're using Java 8+, you could do the same with a Stream on one line (assuming you don't need to preserve the reverse sorted List) like

System.out.println(IntStream.of(1, 5, 10, 6).boxed().sorted(Comparator
            .reverseOrder()).collect(Collectors.toList()));