Created
October 16, 2022 15:15
-
-
Save rmg007/b3074e2fc3b6b1fa26d31a39e52fc5c8 to your computer and use it in GitHub Desktop.
Sort String By Second Char
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 SortStringBySecondChar { | |
public static void main(String[] args) { | |
List<String> list = new ArrayList<>(List.of("Byyyyyyyyyyyy", "Dww", "Cxxxxxx", "az")); | |
Comparator<String> sortBySecondCharComparator = (s1, s2) -> Integer.compare(s2.charAt(1), s1.charAt(1)); | |
list.sort(sortBySecondCharComparator); | |
System.out.println(list); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment