I want to store LinkedHashMap
value into double
type array
. How to do that ?
I tried in this way
Double[] avg= (Double[]) averageMap.values().toArray();
where averageMap
is:
LinkedHashMap<String, Double> averageMap = new LinkedHashMap<String, Double>();
but I have the following exception :
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.Double;
Below code will work for you but its not good enough
averageMap.values().toArray();
method returns object[] so you have to cast it to Double or pars it to double[]but its not good practice to parse it to double.instead of double use Double class.it is wrapper class so autoboxing done automatically so no need to worry