We would like to know how to sort a list with Lambda.
import java.util.Arrays; import java.util.Collections; import java.util.List; //from w w w . j a v a2 s.co m public class Main { public static void main(String... args) { List<String> names = Arrays.asList("XML", "Java", "HTML", "CSS"); Collections.sort(names, (String a, String b) -> b.compareTo(a)); System.out.println(names); Collections.sort(names, (a, b) -> b.compareTo(a)); System.out.println(names); } }
The code above generates the following result.