![](/img/trans.png)
[英]Java - Stream API: custom reduce function to find a minimum
[英]How to find the average value of the stream using the "reduce" function in Java Stream API?
我有:
Stream.of(120, 410, 85, 32, 314, 12)
我試過了,但似乎不對:
Stream.of(120, 410, 85, 32, 314, 12).reduce((a, b) -> b * b / a);
這是解決它的更簡單方法:
double average = IntStream.of(120, 410, 85, 32, 314, 12)
.average()
.getAsDouble();
System.out.println(average);
Output:
162.16666666666666
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.