File tree Expand file tree Collapse file tree 2 files changed +13
-11
lines changed
src/main/java/com/xu/java8/Stream Expand file tree Collapse file tree 2 files changed +13
-11
lines changed Original file line number Diff line number Diff line change 259
259
*/
260
260
list.stream()
261
261
.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")))
264
266
.forEach(System.out::println);
267
+
265
268
/**
266
269
* 找到最小的money
267
270
*/
268
271
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();
274
276
System.out.println(min);
277
+
275
278
/**
276
279
* 计算type的数目
277
280
*/
Original file line number Diff line number Diff line change @@ -52,10 +52,9 @@ public static void main(String args[]) {
52
52
*/
53
53
Integer min = list .stream ()
54
54
.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 ();
59
58
System .out .println (min );
60
59
/**
61
60
* 计算type的数目
You can’t perform that action at this time.
0 commit comments