Hi everyone
I want to add some data to an ArrayList array, but the latter data just covers the former one, while the size of the array is growing (I learned Java for 4 months by myself and did not take any data structure courses in my college...)
here is the code (they are in the same class):
ArrayList<ArrayList<ArrayList<Double>>> all = new ArrayList<ArrayList<ArrayList<Double>>>();
ArrayList<ArrayList<Double>> calcOutput(ArrayList<ArrayList<Double>> input) throws Exception {
ArrayList<ArrayList<Double>> out = new ArrayList<ArrayList<Double>>();
//calculation;
return out;
}
void allfire(ArrayList<ArrayList<ArrayList<Double>>> tch) throws Exception {
for (int p = 0; p < tch.size(); p++) {
all.add(calcOutput(tch.get(p)));
}
it happens that for p=1 or 2 or else, data in all is always changed to the last data added into all
how does this happen and how to solve it?
Thanks very much