kod*_*k98 4 java lambda java-8
在Java 8中,我们有像这样的lambdas
a.sort((v1, v2) -> {});
Run Code Online (Sandbox Code Playgroud)
如何在Java 7中实现此功能?
Java 7和8之间存在2个与此问题相关的差异.
List没有sort方法.你必须使用Collections.sort.->)不是该语言的一部分.Java 7的等价物是
Collections.sort(list, new Comparator<Integer>() {
@Override
public int compare(Integer v1, Integer v2) {
// Write what you need here.
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1068 次 |
| 最近记录: |