TAGS :Viewed: 9 - Published at: a few seconds ago

[ 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.

 ArrayList&lt;HashMap&lt;String, Double[]&gt;&gt; arl =(ArrayList&lt;HashMap&lt;String, Double[]&gt;&gt;)pd.getArrayList();

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

How do I get all the entries into single array of double[].

Answer 1


You're making the same mistake again. You need to add Double to list, not arrays of 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[]{});