当前位置:网站首页>Reduce -- traverse element calculation. The specific calculation formula needs to be passed in and combined with BigDecimal
Reduce -- traverse element calculation. The specific calculation formula needs to be passed in and combined with BigDecimal
2022-07-02 19:07:00 【yuhui66666688gfbfdy】
reduce-- Traversal element calculation The specific calculation formula needs to be passed in combination BigDecimal
@Test
public void testReduce() {
Stream<Integer> stream = Arrays.stream(new Integer[]{1, 2, 3, 4, 5, 6, 7, 8});
Stream<BigDecimal> stream1 = Arrays.stream(new BigDecimal[]{1, 2, 3, 4, 5, 6, 7, 8});
No return 0
BigDecimal sum = stream1.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
// Find that the set elements only sum with The initial value is 0
Integer result = stream.reduce(0, Integer::sum);
System.out.println(result);
stream = Arrays.stream(new Integer[]{1, 2, 3, 4, 5, 6, 7});
// Sum up
stream.reduce((i, j) -> i + j).ifPresent(System.out::println);
stream = Arrays.stream(new Integer[]{1, 2, 3, 4, 5, 6, 7});
// For maximum
stream.reduce(Integer::max).ifPresent(System.out::println);
stream = Arrays.stream(new Integer[]{1, 2, 3, 4, 5, 6, 7});
// For the minimum
stream.reduce(Integer::min).ifPresent(System.out::println);
stream = Arrays.stream(new Integer[]{1, 2, 3, 4, 5, 6, 7});
// Make logic
stream.reduce((i, j) -> i > j ? j : i).ifPresent(System.out::println);
stream = Arrays.stream(new Integer[]{1, 2, 3, 4, 5, 6, 7});
// Seeking logic and opportunity
int result2 = stream.filter(i -> i % 2 == 0).reduce(1, (i, j) -> i * j);
Optional.of(result2).ifPresent(System.out::println);
}
边栏推荐
- Yolov3 trains its own data set to generate train txt
- R language ggplot2 visualization: gganimate package creates dynamic histogram animation (GIF) and uses transition_ The States function displays a histogram step by step along a given dimension in the
- 中国信通院《数据安全产品与服务图谱》,美创科技实现四大板块全覆盖
- 深度学习数学基础
- 在纽约寻找童真——新泽西州乐高乐园探索中心的美好一天
- ICDE 2023|TKDE Poster Session(CFP)
- 论文导读 | 机器学习在数据库基数估计中的应用
- yolov3 训练自己的数据集之生成train.txt
- Golang concurrent programming goroutine, channel, sync
- R语言dplyr包filter函数筛选dataframe数据、如果需要筛选的数据列(变量)名称中包含引号则需要使用!!sym语法处理、否则因为无法处理引号筛选不到任何数据
猜你喜欢

电商系统中常见的 9 大坑,你踩过没?

【JVM调优实战100例】03——JVM堆调优四例

学生抖音宣传母校被吐槽“招生减章”,网友:哈哈哈哈哈哈

中国信通院《数据安全产品与服务图谱》,美创科技实现四大板块全覆盖

Processing strategy of message queue message loss and repeated message sending

消息队列消息丢失和消息重复发送的处理策略

Troubleshooting: kubectl reports an error validationerror: unknown field \u00a0

【每日一题】第二天

Talk about the design of red envelope activities in e-commerce system

juypter notebook 修改默认打开文件夹以及默认浏览器
随机推荐
How can retail enterprises open the second growth curve under the full link digital transformation
产品经理应具备的能力
STM32G0 USB DFU 升级校验出错-2
How to delete the border of links in IE? [repeat] - how to remove borders around links in IE? [duplicate]
SQL training 2
新加坡暑假旅游攻略:一天玩转新加坡圣淘沙岛
Industrial software lecture - core technology analysis of 3D CAD design software - the second lecture of the Forum
[daily question] the next day
[100 cases of JVM tuning practice] 01 - introduction of JVM and program counter
R language uses lrtest function of epidisplay package to perform likelihood ratio test on multiple GLM models (logisti regression). Compare whether the performance of the two models is different, and
R语言dplyr包filter函数筛选dataframe数据、如果需要筛选的数据列(变量)名称中包含引号则需要使用!!sym语法处理、否则因为无法处理引号筛选不到任何数据
R language uses Cox of epidisplay package Display function obtains the summary statistical information of Cox regression model (risk rate HR, adjusted risk rate and its confidence interval, P value of
医院在线问诊源码 医院视频问诊源码 医院小程序源码
R语言ggplot2可视化:gganimate包创建动态柱状图动画(gif)、使用transition_states函数在动画中沿给定维度逐步显示柱状图
聊聊电商系统中红包活动设计
开源物联网平台ThingsBoard的安装
Talk about the design of red envelope activities in e-commerce system
@Component cannot get Dao layer
options should NOT have additional properties
Excel查找一列中的相同值,删除该行或替换为空值