
32

怎么用Lambda求和并且进行类型转换
source link: https://www.oschina.net/question/3447476_2323086
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

怎么用Lambda求和并且进行类型转换
List<String> list = new ArrayList();
list.add("1.1");
list.add("2");
list.add("3.5");
我想用Lambda对list求和,并且转换成BigDecimal类型
list.stream().reduce((a,b)-> String.valueOf(new BigDecimal(a).add(new BigDecimal(b))) 这里返回的是String类型的
以下是问题补充:
@kakai:double v = list.stream().mapToDouble(Double::parseDouble).sum();
(53分钟前)
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK