Last active
September 22, 2016 02:32
-
-
Save youzipi/92a121acf9be52121fe17c92f881475c to your computer and use it in GitHub Desktop.
stream,collection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Integer[] array= new Integer[]{1,2,3}; | |
List<Integer> list = Arrays.asList(array); | |
List<Integer> list2 = Arrays.asList(1,2,3); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
productList.stream() | |
.collect(summingLong(Product::getGoodsNum)); | |
// equals to | |
productList.stream() | |
.map(Product::getGoodsNum) | |
.reduce(0L, (sumNum, num) -> sumNum += num); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Map<Long, ShoppingCart> idAndCarts = curShoppingCarts.stream() | |
.collect(Collectors.toMap( | |
ShoppingCart::getGoodsInfoId, | |
cart -> cart // equal to `identity()` | |
// , | |
// (k, v) -> v | |
)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment