当前位置:网站首页>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);
}
边栏推荐
- UML class diagram
- 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
- 全链路数字化转型下,零售企业如何打开第二增长曲线
- The difference between promise and observable
- 学生抖音宣传母校被吐槽“招生减章”,网友:哈哈哈哈哈哈
- 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
- 鸿蒙第四次学习
- 【测试开发】一文带你了解什么是软件测试
- juypter notebook 修改默认打开文件夹以及默认浏览器
- 2022编译原理期末考试 回忆版
猜你喜欢

论文导读 | 机器学习在数据库基数估计中的应用

ICDE 2023|TKDE Poster Session(CFP)

High frequency interview questions

新加坡暑假旅游攻略:一天玩转新加坡圣淘沙岛

yolov3 训练自己的数据集之生成train.txt

聊聊电商系统中红包活动设计
![[0701] [论文阅读] Alleviating Data Imbalance Issue with Perturbed Input During Inference](/img/c7/9b7dc4b4bda4ecfe07aec1367fe059.png)
[0701] [论文阅读] Alleviating Data Imbalance Issue with Perturbed Input During Inference

M2DGR:多源多场景 地面机器人SLAM数据集(ICRA 2022 )

Hospital online inquiry source code hospital video inquiry source code hospital applet source code

Distance measurement - Jaccard distance
随机推荐
Looking for innocence in New York -- a beautiful day at the discovery center of Legoland, New Jersey
27: Chapter 3: develop Passport Service: 10: [registration / login] interface: after the registration / login is OK, save the user session information (uid, utoken) to redis and cookies; (one main poi
使用CLion编译OGLPG-9th-Edition源码
STM32G0 USB DFU 升级校验出错-2
Stm32g0 USB DFU upgrade verification error -2
【每日一题】第二天
R语言dplyr包na_if函数把向量数值中的控制转化为缺失值NA、按照映射规则把指定内容转化为缺失值NA
"Patient's family, please come here" reading notes
The text editor hopes to mark the wrong sentences in red, and the text editor uses markdown
Troubleshooting: kubectl reports an error validationerror: unknown field \u00a0
How to delete the border of links in IE? [repeat] - how to remove borders around links in IE? [duplicate]
[Yugong series] July 2022 go teaching course 001 introduction to go language premise
[100 cases of JVM tuning practice] 03 -- four cases of JVM heap tuning
juypter notebook 修改默认打开文件夹以及默认浏览器
LightGroupButton* sender = static_ cast<LightGroupButton*>(QObject::sender());
9D电影是怎样的?(+维度空间常识)
Websocket of Web real-time communication technology
FastDFS安装
【JVM调优实战100例】03——JVM堆调优四例
QT中的QPropertyAnimation使用和toast案列