Java知识碎片
数组转List集合
1.String[]
String[] stringArray = {"hello","world","B"};
List<String> stringB = Arrays.asList(stringArray);
1
2
2
2.int[]
int[] intArray = {1, 2, 3, 4};
List<Integer> list = Ints.asList(intArray);
//Java List集合过滤,不用写双重for循环这么麻烦了
String condition="K101,1461";
//根据条件过滤出符合的车次-只保留K101,1461车次
if (condition != null && !condition.equals("")) {
condition=condition.toUpperCase();
List<String> lsFilter=Arrays.asList(condition.split(","));
finalTickets= finalTickets.stream()
.filter((TicketInfo info) -> lsFilter.contains(info.getStation_train_code().toUpperCase()))
.collect(Collectors.toList());
}
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
List集合过滤
不用写双重for循环这么麻烦了
String condition="K101,1461";
//根据条件过滤出符合的车次-只保留K101,1461车次
if (condition != null && !condition.equals("")) {
condition=condition.toUpperCase();
List<String> lsFilter=Arrays.asList(condition.split(","));
finalTickets= finalTickets.stream()
.filter((TicketInfo info) -> lsFilter.contains(info.getStation_train_code().toUpperCase()))
.collect(Collectors.toList());
}
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9