First of all, your code looks very very bad-written.
ArrayList al=new ArrayList(); // why do your instantiate an instance here?
MyObject mo=new MyObject(); // why do your instantiate an instance here?
TestArrayList tal=new TestArrayList();
al=tal.getObjectList();
solution: remove the unnecessary new.
// Do you realise that every time this method being invoked, your created two more instance? They will hit the performance bottleneck one day.
public ArrayList getObjectList(){
ArrayList al=new ArrayList();
MyObject mo=new MyObject();
mo.setItemCode("001");
mo.setItemName("one");
al.add(mo);
mo.setItemCode("002");
mo.setItemName("two");
al.add(mo);
mo.setItemCode("003");
mo.setItemName("three");
al.add(mo);
return al;
}
solution: refactor this method is required.
And to answer your question, yes, your guess is right. Object references are added into the Arraylist, hence changing one will affect the others.
Regards,
Jiafan