StreamEx 13-カスタムセットを削減()
package day15;
import java.util.Arrays;
import java.util.List;
public class StreamEx13 {
public static void main(String[] args) {
List<Student> stdList = Arrays.asList(
new Student("aaaa", 10),
new Student("bbbb", 20),
new Student("cccc", 30),
new Student("dddd", 40)
);
int sum = stdList.stream()
.mapToInt(Student::getScore)
.sum();
int sum2 = stdList.stream()
.map(Student::getScore)
.reduce((a, b) -> a + b)
.get();
int sum3 = stdList.stream()
.mapToInt(Student::getScore)
.reduce(0, (a,b)-> a+b);
System.out.println("sum1 : " + sum);
System.out.println("sum2 : " + sum2);
System.out.println("sum3 : " + sum3);
}
}
Reference
この問題について(StreamEx 13-カスタムセットを削減()), 我々は、より多くの情報をここで見つけました https://velog.io/@jonny77/StreamEx13-커스텀-집계-reduceテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol