I have a problem to deep copy an ArrayList containing Attribute objects. After I have copied the ArrayList dataSet in a new one called trainingSet, I am trying to clear (of the trainingSet) all the content of the internal ArrayList of the Attribute called data. When I do so all the same content of the the ArrayList dataSet (data of dataSet) gets cleared, too. So in that case I have tried to deep copy all the content of the original list to the new one using the below tuts:
but I got the same behavior. So can someone please tell me how I can fix this problem and where the wrong thinking is?
Thank you for help.
ID3Algorithm.java
...
ArrayList<Attribute> dataSet = new ArrayList<dataSet>();
ArrayList<Attribute> trainingSet = new ArrayList<Attribute>(dataSet);
for(Attribute att : trainingSet) {
  att.GetData().clear();  // At this point all the data in dataSet are cleared,too.
}
...
Attribute.java
public class Attribute
{
  private String name;  
  private ArrayList<String> branchNames = new ArrayList<String>();      
  private ArrayList<String> data = new ArrayList<String>(); 
  private ArrayList<Branch> branches = new ArrayList<Branch>(); 
  private HashMap<String, Integer> classes = new HashMap<String, Integer>();
  private ID3Algorithm id3;
  private Leaf leaf = null;
  public ArrayList<String> GetData() { return data; }
  public Attribute(String attribName, ArrayList<String> attribBranchNames, ArrayList<String> attribData, ID3Algorithm algo) {
    name = attribName;
    branchNames = attribBranchNames;
    data = attribData;
    id3 = algo;             
  }
  ...
}
 
    