forked from DreamCats/java-notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest2.java
More file actions
36 lines (32 loc) · 1020 Bytes
/
Test2.java
File metadata and controls
36 lines (32 loc) · 1020 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
* @program JavaBooks
* @description: 带参数的简写
* @author: mf
* @create: 2020/08/04 21:14
*/
package lmd;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class Test2 {
public static void main(String[] args) {
// jdl7
List<String> list = Arrays.asList("I", "love", "you", "too");
int[] array = list.stream().mapToInt(Integer::valueOf).toArray();
// 按长度排序
// Collections.sort(list, new Comparator<String>() { // 接口 匿名
// @Override
// public int compare(String o1, String o2) {
// if (o1 == null)
// return -1;
// if (o2 == null)
// return 1;
// return o1.length() - o2.length();
// }
// });
// System.out.println(list.toString());
// java 8
Collections.sort(list, (o1, o2) -> o1.length() - o2.length());
System.out.println(list.toString());
}
}