基本信息
源码名称:java lamda 详细案例
源码大小:1.48M
文件格式:.rar
开发语言:Java
更新时间:2020-09-08
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
java lamda详细案例
public class MapReduce01 {
public static void main(String[] args) {
List<Car> all = new ArrayList<>();
all.add(new Car("西游记", 400, 45.89));
all.add(new Car("水浒传", 500, 32.73));
all.add(new Car("红楼梦", 300, 37.25));
all.add(new Car("三国演义", 600, 53.76));
/*| | / /
| | / /
| | / /
| |/ /-.__
| ` _/ / )
| /` ) / /
| / /_/\_/\
|/ / |
( ' \ '- |
\ `. /
| |*/
// 每本书各自总价
all.stream().
map(myCar -> {
System.out.print("书名:" myCar.getPname() ";总价:");
return myCar.getAmount() * myCar.getPrice();
}).forEachOrdered(System.out::println);
// 全部书总价
double result = all.stream().
map((myCar) -> { return myCar.getAmount() * myCar.getPrice();}).
reduce((sum, carPrice) -> sum carPrice).get();
System.out.println("总价:" result);
// 数据统计
DoubleSummaryStatistics stat=all.stream()
.mapToDouble(mycar->{return mycar.getAmount()*mycar.getPrice();}).summaryStatistics();
System.out.println("统计量:" stat.getCount());
System.out.println("最大值:" stat.getMax());
System.out.println("最小值:" stat.getMin());
System.out.println("平均值:" stat.getAverage());
System.out.println("合计值:" stat.getSum());
}
java lamda详细案例
public class MapReduce01 {
public static void main(String[] args) {
List<Car> all = new ArrayList<>();
all.add(new Car("西游记", 400, 45.89));
all.add(new Car("水浒传", 500, 32.73));
all.add(new Car("红楼梦", 300, 37.25));
all.add(new Car("三国演义", 600, 53.76));
/*| | / /
| | / /
| | / /
| |/ /-.__
| ` _/ / )
| /` ) / /
| / /_/\_/\
|/ / |
( ' \ '- |
\ `. /
| |*/
// 每本书各自总价
all.stream().
map(myCar -> {
System.out.print("书名:" myCar.getPname() ";总价:");
return myCar.getAmount() * myCar.getPrice();
}).forEachOrdered(System.out::println);
// 全部书总价
double result = all.stream().
map((myCar) -> { return myCar.getAmount() * myCar.getPrice();}).
reduce((sum, carPrice) -> sum carPrice).get();
System.out.println("总价:" result);
// 数据统计
DoubleSummaryStatistics stat=all.stream()
.mapToDouble(mycar->{return mycar.getAmount()*mycar.getPrice();}).summaryStatistics();
System.out.println("统计量:" stat.getCount());
System.out.println("最大值:" stat.getMax());
System.out.println("最小值:" stat.getMin());
System.out.println("平均值:" stat.getAverage());
System.out.println("合计值:" stat.getSum());
}