Garmaine Staff asked 7 years ago

I'm trying to loop a list and that list have 4 arrays inside and each array have 7 values

I am looping the list and then when I get an array from the list, since I know how many values have the array I assign each array index like this: personObject.setName(String.valueOf(myArray[0]) and then at the end of the while loop I add to a list of Persons the personObject like this: listOfPersons.add(personObject).

My problem is that my list only gets populate with the same object and I know that the 4 arrays inside the list that I'm looping have different values, here is my code:

ArrayList<Object> objectList= null;
objectList= _serviceVariable.getObjects(); <--- this works it returns a list with 4 arrays all with diferent values

Person myPerson = new Person();
List<Person> personsList = new List<Person>; 

Iterator<Object> itr = objectList.iterator();

Object[] innerObj = (Object[]);

myPerson.setName(String.valueOf(innerObj [0])
myPerson.setLastName(String.valueOf(innerObj [1])
myPerson.setNickName(String.valueOf(innerObj [2])


when I print my persons list is full of persons with the same name, lastName and nick name, is a list full of the same objects with the same values.