If you store any object in ArrayList, Object is not replicated and any change in object should reflect in object itself.
for example we have class NewClass
public class NewClass {
private String mystring="";
/**
* @return the mystring
*/
public String getMystring() {
return mystring;
}
/**
* @param mystring the mystring to set
*/
public void setMystring(String mystring) {
this.mystring = mystring;
}
}
here is code in main method of any other class
List<NewClass> newclasses = new ArrayList<NewClass>();
NewClass class1 = new NewClass();
class1.setMystring("before1");
NewClass class2 = new NewClass();
class2.setMystring("before2");
newclasses.add(class1);
newclasses.add(class2);
newclasses.get(0).setMystring("after1");
System.out.println(class1.getMystring());
This will output after1.