简体   繁体   English

数组列表 <Hashmap<String,Double[]> 将值分配给单个Double []

[英]ArrayList<Hashmap<String,Double[]> assigning the values to a single Double[]

I am able to assign the Hash-map values to List double[] using following code, but for each entry in the Hash-map, it is creating separate array. 我可以使用以下代码将Hash-map值分配给List double [],但是对于Hash-map中的每个条目,它将创建单独的数组。

 ArrayList<HashMap<String, Double[]>> arl =(ArrayList<HashMap<String, Double[]>>)pd.getArrayList();

 while (itr.hasNext()) {
     HashMap< String,Double[]> map = (HashMap<String,Double[]>) itr.next();
     empid.add((Double[])map.get("id"));
 }

How do I get all the entries into single array of double[]. 如何将所有条目放入double []的单个数组中。

You're making the same mistake again. 您再次犯了同样的错误。 You need to add Double to list, not arrays of Double. 您需要将Double添加到列表,而不是Double数组。 So similarly to what I said in your previous question , change your code like this: 因此,与我在上一个问题中所说的类似,请更改您的代码,如下所示:

empid.addAll(Arrays.asList(map.get("id"))));

To get array from the list after the list is fully built with values from your map: 要使用列表中的值完全构建列表后,从列表中获取数组:

Double[] arrayOfDoubles = empid.toArray(new Double[]{});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM