Created
October 16, 2022 13:51
-
-
Save rmg007/188d2992835ed8a4bf5158d152d7a34e to your computer and use it in GitHub Desktop.
Sort List using Comparator NaturalOrder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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