Its very simple but somehow not working (weird!!).
I have a List of a class type. I am adding objects to the list in a for loop. Up till adding object everything is Ok,
You need create a new myClassObj every time, your code uses the same object reference.
List<myClass> myClassList = new ArrayList<myClass>();
for(int i=0;i<someArray.length;i++){
myClass myClassObj = new myClass(); // HERE
myClassObj.setProperty1("value1");
...
System.out.println(myClassList.add(myClassObj));////////////////////////
}
When populating the list, you are repeatedly adding references to the same object. To fix, move the myClassObj
initialization into the loop:
for(int i=0;i<someArray.length;i++){
myClass myClassObj = new myClass(); // <---- moved this into the loop
myClassObj.setProperty1("value1");
This will create a separate object for every element of the list.