Skip to content

Instantly share code, notes, and snippets.

@youzipi
Last active September 22, 2016 02:32
Show Gist options
  • Save youzipi/92a121acf9be52121fe17c92f881475c to your computer and use it in GitHub Desktop.
Save youzipi/92a121acf9be52121fe17c92f881475c to your computer and use it in GitHub Desktop.
stream,collection
Integer[] array= new Integer[]{1,2,3};
List<Integer> list = Arrays.asList(array);
List<Integer> list2 = Arrays.asList(1,2,3);
productList.stream()
.collect(summingLong(Product::getGoodsNum));
// equals to
productList.stream()
.map(Product::getGoodsNum)
.reduce(0L, (sumNum, num) -> sumNum += num);
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