Java – add value for double [] ArrayList
•
Java
I have the following array
ArrayList<double[]> db_results = new ArrayList<double[]>();
I want to add such a value
db_results.add(new double[] {0,1,2});
But cycles like this
for ( int i = 0 ; i <= 2; i++) { double val = Double.parseDouble(i); db_results.add(new double[] {val}); }
Obviously, this is adding a new array each time using a single value... So how do you add it to an array?
Solution
double[] nums = new double[3];
double[] nums = new double[3]; for ( int i = 0 ; i <= 2; i++) { double val = Double.parseDouble(i); nums[i] = val; } db_results.add(nums);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码