I just wrote this function to add values into Multidimensional arraylist, but dont get it why all added values overwrites into recent added value. I need to figure out why this happening. As javadoc says it has to act like this " Appends the specified element to the end of this list". And i dont see any place at his code, where previously added value could be overwriten . One more strange thing is that size of array increases
Here is my output:
[0.4, 0.42, 0.4, 1.2200000000000002, 0.0010000000000000009] after add 0
[0.4, 0.42, 0.4, 1.2200000000000002, 0.0010000000000000009] after add 1
[0.4, 0.42, 0.4, 1.2200000000000002, 0.0010000000000000009] after add 2
[0.4, 0.42, 0.4, 1.2200000000000002, 0.0010000000000000009] after add 3
[0.4, 0.42, 0.4, 1.2200000000000002, 0.0010000000000000009] after add 4
[0.4, 0.42, 0.42, 1.24, 0.01200000000000001] after add 0
[0.4, 0.42, 0.42, 1.24, 0.01200000000000001] after add 1
[0.4, 0.42, 0.42, 1.24, 0.01200000000000001] after add 2
[0.4, 0.42, 0.42, 1.24, 0.01200000000000001] after add 3
[0.4, 0.42, 0.42, 1.24, 0.01200000000000001] after add 4
[0.4, 0.42, 0.42, 1.24, 0.01200000000000001] after add 5
[0.4, 0.44, 0.4, 1.2400000000000002, 0.011999999999999983] after add 0
[0.4, 0.44, 0.4, 1.2400000000000002, 0.011999999999999983] after add 1
[0.4, 0.44, 0.4, 1.2400000000000002, 0.011999999999999983] after add 2
[0.4, 0.44, 0.4, 1.2400000000000002, 0.011999999999999983] after add 3
[0.4, 0.44, 0.4, 1.2400000000000002, 0.011999999999999983] after add 4
[0.4, 0.44, 0.4, 1.2400000000000002, 0.011999999999999983] after add 5
[0.4, 0.44, 0.4, 1.2400000000000002, 0.011999999999999983] after add 6
And here is my function:
public void createArrayList(ArrayList<Double> list,ArrayList<Double>
listLaid,int size,double sum, double absValue){
ArrayList<Double> workArray = new ArrayList<>();
ArrayList<ArrayList<Double>>
workMatrix= new ArrayList<>();
double abs=0;
for(int a = 0; a < size ;a++){
for(int b = 0; b < size ; b++){
for (int c = 0 ; c < size; c++){
abs =Math.abs(sum - list.get(a) - list.get(b) - list.get(c));
if( abs <= absValue){
double totalSum = listLaid.get(a) + listLaid.get(b) +
listLaid.get(c);
workArray.clear();
workArray.add(listLaid.get(a));
workArray.add(listLaid.get(b));
workArray.add(listLaid.get(c));
workArray.add(totalSum);
workArray.add(abs);
workMatrix.add(workArray);
}
}
}
}
}
for (int i = 0; i < workMatrix.size(); i++)
System.out.println(darbineMat.get(i)+" after add "+i);