JavaListsort

Sorts the list using the given comparator.

Syntax

list.sort(comparator)

Example

Enter values below to update the example in real time.

import
java
util
Collections
List
list
new
ArrayList
of
sort
System
out
println
import java.util.Collections;
List<Integer> list = new ArrayList<>(List.of(3, 1, 4, 1, 5));
Collections.sort(list);
System.out.println(list); // [1, 1, 3, 4, 5]