Online Java Compiler By
JavaTpoint.com
import java.util.*; public class CollectionsReverseOrderExample3 { public static void main(String[] args) { //Create Array list object List
list = Arrays.asList("Jaya", "Pratham", "Ruby", "Commit"); Collections.sort(list, Collections.reverseOrder (CollectionsReverseOrderExample3::lastCharComparator)); //Sort the list according to last character of word and return comparator for reverse order System.out.println(list); } private static int lastCharComparator(String s1, String s2) { return Character.compare(s1.charAt(s1.length() - 1), s2.charAt(s2.length()-1)); } }
Output