I am trying to create a unique list. I can not use a "Set" because I need to assign some of the values as I iterate though it.
Right now I doing this to create a unique list. Does anyone know a better way?
List<Thing> things = previousThings.stream()
.collect(Collectors.toSet()).stream()
.collect(Collectors.toList());
I was thinking that if I convert it to a set and the back to a list it would eliminate any duplicate entries. I think it needs to be a list so that I can use "List.set(..)" to update according to what might already be in my repository.
for(int i = 0; i < things.size(); i++) {
if(things.get(i).id == null) {
existingThing = thingRepository.getByName(things.get(i).getName());
if(existingThing != null) {
things.set(i, existingThing);
} else {
things.set(i, thingRepository.save(things.get(i));
}
}
}