storing a string arraylist into a double arraylist?

廉价感情. 提交于 2019-12-03 09:01:22

You cant use a , in your value to parse to a double

Try:

double total_ary = Double.parseDouble(value.replace(",","."));
  ArrayList<String> hello = new ArrayList<>();

    double[] bye = new double[hello.size()]; 

    for (int i = 0; i < hello.size(); ++i) { 
        bye[i] = Double.parseDouble(hello.get(i)); 
    }

Before Double.parseDouble(value) replace "," with "."

Try:

List<Double> list2 = totals.stream().map(c -> c.replace(",",".")).map(Double::parseDouble).collect(Collectors.toList());
Double sum = list2.stream().reduce((x,y)->x+y).get();

Or if you just want the sum:

Double sum = totals.stream.map(c -> c.replace(",",".")).map(Double::parseDouble).reduce((x,y)->x+y).get();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!