Skip to content

Commit 63c8724

Browse files
committed
stream
1 parent abf5413 commit 63c8724

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/main/java/com/xu/java8/Stream/Stream.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -259,19 +259,22 @@
259259
*/
260260
list.stream()
261261
.filter(x -> JSONObject.fromObject(x).containsKey("money"))
262-
.sorted((b, a) -> Integer.valueOf(JSONObject.fromObject(a).getInt("money")).compareTo(JSONObject.fromObject(b)
263-
.getInt("money")))
262+
.sorted((b, a) -> Integer.valueOf(JSONObject.fromObject(a)
263+
.getInt("money"))
264+
.compareTo(JSONObject.fromObject(b)
265+
.getInt("money")))
264266
.forEach(System.out::println);
267+
265268
/**
266269
* 找到最小的money
267270
*/
268271
Integer min = list.stream()
269-
.filter(x -> JSONObject.fromObject(x).containsKey("money"))
270-
.map(x -> JSONObject.fromObject(x).getInt("money"))
271-
.sorted()
272-
.findFirst()
273-
.get();
272+
.filter(x -> JSONObject.fromObject(x).containsKey("money"))
273+
.mapToInt(x -> JSONObject.fromObject(x).getInt("money"))
274+
.min()
275+
.getAsInt();
274276
System.out.println(min);
277+
275278
/**
276279
* 计算type的数目
277280
*/

src/main/java/com/xu/java8/Stream/Streams6.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,9 @@ public static void main(String args[]) {
5252
*/
5353
Integer min = list.stream()
5454
.filter(x -> JSONObject.fromObject(x).containsKey("money"))
55-
.map(x -> JSONObject.fromObject(x).getInt("money"))
56-
.sorted()
57-
.findFirst()
58-
.get();
55+
.mapToInt(x -> JSONObject.fromObject(x).getInt("money"))
56+
.min()
57+
.getAsInt();
5958
System.out.println(min);
6059
/**
6160
* 计算type的数目

0 commit comments

Comments
 (0)