List<double[]> x = new ArrayList<double[]>(); x.add(new double[]={1,2,3,4,54,6});
elements 1,2,3,4,54,6 are added to x
x.get(0) ---> returns 1
But doing this, address of array is added? why
List<double[]> x = new ArrayList<double[]>(); double[] name=new double[5]; name[0]=1 name[1]=3; name[2]=3; . . . . x.add(name); getting x.get(0) ---> returns @as12cd2 (address of the array)
If you just want your list to store the doubles instead of arrays of doubles, change what the list is storing
List<Double> doubleList = new ArrayList<Double>();
Then you can add the array as a list to your array list which will mean the list is storing the values rather than the array. This will give you the behaviour that get(0)
will give you 1 rather than the array address
Double[] doubleArray = {1.0, 2.0, 3.0, 4.0, 54.0, 6.0 }; doubleList.addAll(Arrays.asList(doubleArray)); doubleList.get(0); //gives 1.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With