list 常见的统计(求和、最大、最小、平均)
最新推荐文章于 2024-09-21 00:37:16 发布
package .list_test; import ; import ; /** * 描述:ListTest3 * * @author 何志鹏 * @ClassName:ListTest3 * @create 2019-05-30 18:49 * Version 1.0 */ public class ListTest3 { public static void main(String[] args) { List<Student> list = new ArrayList<>(); Student s1 = new Student(); (1); ("张三"); (28); Student s2 = new Student(); (2); ("李四"); (29); Student s3 = new Student(); (3); ("网二"); (30); (s1); (s2); (s3); ("=========第一种方式================"); int suma = ().map(e -> ()).reduce(Integer::sum).get();//求和 (suma); int maxa = ().map(e -> ()).reduce(Integer::max).get();//最大 (maxa); int mina = ().map(e -> ()).reduce(Integer::min).get();//最小 (mina); ("=========第二种方式================"); double doublesum = ().mapToDouble(Student::getAge).sum();//和 (doublesum); int intmax = ().mapToInt(Student::getAge).max().getAsInt();//最大 (intmax); int intmin = ().mapToInt(Student::getAge).min().getAsInt();//最小 (intmin); double avg = ().mapToDouble(Student::getAge).average().getAsDouble();//平均 (avg); } }