I'm having problem with using ArrayList. First I'm new to Java, I'm trying to use ArrayList to store objects and now I want to print out all objects thats are items of the ArrayList. But somehow, the List printed out improperly, there are duplicated items (i'm sure there is only one item of them). Here are my code:
StringBuilder description = new StringBuilder();
for (Unit u: diary.getUnitCollection()){
for (AssessmentItem a: u.getAssessmentCollection()){
for (Task t: a.getTaskCollection()){
description.append(t.toString());
}
description.append(a.toString());
}
description.append(u.toString());
}
and this is the result, as you can see, they are duplicated:
Java-Ass1
Java-Ass2
Java-Ass1
Java-Ass2
If I print the UnitCollection only, its display correctly but the format like this [item,..], I want to know what's wrong in the for loop.
toString().