Skip to content

Instantly share code, notes, and snippets.

@rmg007
Created October 16, 2022 13:51
Show Gist options
  • Select an option

  • Save rmg007/188d2992835ed8a4bf5158d152d7a34e to your computer and use it in GitHub Desktop.

Select an option

Save rmg007/188d2992835ed8a4bf5158d152d7a34e to your computer and use it in GitHub Desktop.
Sort List using Comparator NaturalOrder
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
public class SortListUsingComparatorNaturalOrder {
public static void main(String[] args) {
List<Integer> list = new ArrayList<>(List.of(3, 6, 8, 2));
list.sort(Comparator.naturalOrder());
System.out.println(list);//output [2, 3, 6, 8]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment