Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

how to sort linked list in java

//
// Sorts a list of strings alphabetically
// Comparator in sorted() can be replaced based on the type of your list
//

List<String> names = List.of("Nikos", "Sofia", "Klelia", "George");
// [Nikos, Sofia, Klelia, George]

List<String> sortedList = names.stream()
                .sorted((o1, o2) -> Collator.getInstance().compare(o1, o2))
                .collect(Collectors.toList());
// [George, Klelia, Nikos, Sofia]
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #sort #linked #list #java
ADD COMMENT
Topic
Name
8+4 =