java8---- compare 汇总

Collections.sort(names, (String a, String b) -> { return b.compareTo(a); });

正如你可以看到的代码更容易阅读。但它甚至更短:
Collections.sort(names, (String a, String b) -> b.compareTo(a));

一行方法的方法体可以跳过{}和参数类型,使它变得更短:
Collections.sort(names, (a, b) -> b.compareTo(a));

https://yq.aliyun.com/articles/17036?spm=a2c4e.11153940.0.0.6a255562myIiAj

原文地址:https://www.cnblogs.com/hahajava/p/12193360.html