I am trying to add an object to an arraylist.
The object is defined as:
ExercisesGroup group = new ExercisesGroup();
Array List defined as:
ArrayList<ExercisesGroup> groups = new ArrayList<ExercisesGroup>();
I am then populating the object in a loop (rs is a result set from a database):
while (rs.next()){
group.setExerciseGroupId(rs.getInt("idbodyarea"));
group.setExerciseGroupDescription(rs.getString("bodyareadescription"));
groups.add(group);
}
When I return the arraylist 'groups' the correct number of results are added, however the data is all the same, i.e. the last record is added for every slot.
<exerciseGroupsReturn>
<exerciseGroupDescription>Description2</exerciseGroupDescription>
<exerciseGroupId>2</exerciseGroupId>
</exerciseGroupsReturn>
<exerciseGroupsReturn>
<exerciseGroupDescription>Description2</exerciseGroupDescription>
<exerciseGroupId>2</exerciseGroupId>
</exerciseGroupsReturn>
Any idea what I am doing wrong?