当前位置:网站首页>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);
}
边栏推荐
- Hospital online inquiry source code hospital video inquiry source code hospital applet source code
- Introduction to the paper | analysis and criticism of using the pre training language model as a knowledge base
- Distance measurement - Jaccard distance
- R language dplyr package filter function filters dataframe data. If the name of the data column (variable) to be filtered contains quotation marks, you need to use!! SYM syntax processing, otherwise n
- 距离度量 —— 杰卡德距离(Jaccard Distance)
- Excel查找一列中的相同值,删除该行或替换为空值
- [paper reading] Ca net: leveraging contextual features for lung cancer prediction
- What is 9D movie like? (+ common sense of dimension space)
- 电商系统中常见的 9 大坑,你踩过没?
- Exness in-depth good article: dynamic series - Case Analysis of gold liquidity (V)
猜你喜欢

Yesterday, Alibaba senior wrote a responsibility chain model, and there were countless bugs

What is 9D movie like? (+ common sense of dimension space)

Looking for innocence in New York -- a beautiful day at the discovery center of Legoland, New Jersey

LightGroupButton* sender = static_ cast<LightGroupButton*>(QObject::sender());

PyTorch函数中的__call__和forward函数

迷你高尔夫球场:伦敦休闲旅游好去处

Comprendre complètement le tutoriel de traitement de Point Cloud basé sur open3d!

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

Deep learning mathematics foundation

Have you stepped on the nine common pits in the e-commerce system?
随机推荐
C的内存管理
【测试开发】一文带你了解什么是软件测试
Comprendre complètement le tutoriel de traitement de Point Cloud basé sur open3d!
PyTorch函数中的__call__和forward函数
Learn the knowledge points of eight part essay ~ ~ 1
R语言dplyr包filter函数筛选dataframe数据、如果需要筛选的数据列(变量)名称中包含引号则需要使用!!sym语法处理、否则因为无法处理引号筛选不到任何数据
[100 cases of JVM tuning practice] 01 - introduction of JVM and program counter
[0701] [paper reading] allowing data imbalance issue with perforated input during influence
The second bullet of AI development and debugging series: the exploration journey of multi machine distributed debugging
Deep learning mathematics foundation
新手必看,点击两个按钮切换至不同的内容
Transformation of thinking consciousness is the key to the success or failure of digital transformation of construction enterprises
[fluent] dart data type (VaR data type | object data type)
高频面试题
R language dplyr package Na_ The if function converts the control in the vector value into the missing value Na, and converts the specified content into the missing value Na according to the mapping r
Excel finds the same value in a column, deletes the row or replaces it with a blank value
Stratégie touristique d'été de Singapour: un jour pour visiter l'île de San taosha à Singapour
在Tensorflow2中使用mnist_784数据集进行手写数字识别
开发固定资产管理系统,开发固定资产管理系统用什么语音
[test development] software testing - concept