I have an list of customer object. I need to read them from shared preferences and check for particular object by id with my new object and replace the old one in list with new object and write it to back to pref. This is what I am doing..Is it right?
List<School> schools = readFromPref();
ListIterator<School> iterator = schools.listIterator();
while (iterator.hasNext()) {
School oldSchool = iterator.next();
if (oldSchool.getId().equalsIgnoreCase(newSchool.getId())) {
iterator.set(newSchool);
schools.add(newSchool);
}
}
writeToPref(schools);