String[] atp = {"Rafael Nadal", "Novak Djokovic",
"Stanislas Wawrinka",
"David Ferrer","Roger Federer",
"Andy Murray","Tomas Berdych",
"Juan Martin Del Potro"};
List<String> players = Arrays.asList(atp);
// java1.7排序
Collections.sort(players, new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
return o1.compareTo(o2);
}
});
System.out.println(players);
// java1.8排序 只针对有一个方法的匿名函数
Collections.sort(players,(s1, s2) -> s1.compareTo(s2));
System.out.println(players);
java1-7和1-8的排序代码
Author: tea9
Permalink: http://tea9.github.io/post/3958752247.html
License: Copyright (c) 2017-2025 CC-BY-NC-4.0 LICENSE
Slogan: Do you believe in DESTINY?