List<Long> idTemp = list.stream().map(SysDept::getDeptId).collect(Collectors.toList());
Long[] deptIds = idTemp.toArray(new Long[idTemp.size()]);
Long[] ids = listDept.stream().map(SysDept::getDeptId).toArray(Long[]::new);
List<ExcelS> list = new ArrayList();
list.add(new ExcelS(new BigDecimal(12),1));
list.add(new ExcelS(new BigDecimal(12),1));
list.add(new ExcelS(new BigDecimal(12),1));
list.add(new ExcelS(new BigDecimal(12),1));
list.add(new ExcelS(new BigDecimal(12),2));
//计算总价格
BigDecimal reduce = list.stream().map(x-> x.getPrice().multiply(new BigDecimal(x.getNum()))).reduce(BigDecimal.ZERO,BigDecimal::add);
System.out.println("总价格-------》"+reduce);
String数组转long数组
Long[] longIds = Arrays.stream(ids).map(str -> Long.parseLong(str.trim())).toArray(Long[]::new);
计算总和
List<ExcelS> list = new ArrayList();
list.add(new ExcelS(new BigDecimal(12),1));
list.add(new ExcelS(new BigDecimal(12),1));
list.add(new ExcelS(new BigDecimal(12),1));
list.add(new ExcelS(new BigDecimal(12),1));
list.add(new ExcelS(new BigDecimal(12),2));
//计算总价格
BigDecimal reduce = list.stream().map(x-> x.getPrice().multiply(new BigDecimal(x.getNum()))).reduce(BigDecimal.ZERO,BigDecimal::add);
System.out.println("总价格-------》"+reduce);
stream简单使用
List<Integer> list = new ArrayList();
list.add(1);
list.add(2);
list.add(4);
list.add(4);
list.add(3);
list.add(5);
//只取前3条数据
Stream limit = list.stream().limit(3);
Iterator iterator = limit.iterator();
while (iterator.hasNext()) {
System.out.println(iterator.next());
}
//排序,默认的排序
Stream sorted = list.stream().sorted();
Iterator iterator1 = sorted.iterator();
while (iterator1.hasNext()) {
System.out.println("iterator1=====" + iterator1.next());
}
//删除前三个skip(3)
Stream skip = list.stream().skip(3);
Iterator iterator2 = skip.iterator();
while (iterator2.hasNext()) {
System.out.println("iterator2=====" + iterator2.next());
}
//获取list长度
System.out.println("count=" + list.stream().count());
//去除重复的
Stream distinct = list.stream().distinct();
Iterator iterator3 = distinct.iterator();
while (iterator3.hasNext()) {
System.out.println("iterator3=====" + iterator3.next());
}
//获取到流进行过滤出二的倍数,并放入到一个数组中
List<Integer> newList2 = list.stream().filter(x -> x % 2 == 0).collect(Collectors.toList());
System.out.println(newList2);
内容转载于
stream流的简单使用_.toarray(long[]::new)-CSDN博客文章浏览阅读222次。stream流的简单使用 List list = new ArrayList(); list.add(1); list.add(2); list.add(4); list.add(4); list.add(3); list.add(5); //只取前3条数据 Stream limit = list.stream().limit(3); _.toarray(long[]::new)https://blog.csdn.net/weixin_46553523/article/details/116453648
stream流的简单使用_.toarray(long[]::new)-CSDN博客文章浏览阅读222次。stream流的简单使用 List list = new ArrayList(); list.add(1); list.add(2); list.add(4); list.add(4); list.add(3); list.add(5); //只取前3条数据 Stream limit = list.stream().limit(3); _.toarray(long[]::new)https://blog.csdn.net/weixin_46553523/article/details/116453648