I have a list of objects as following,
ArrayList<Student> students = new ArrayList<>(
List.of(
Student.builder().id(1L).name("Joe").build(),
Student.builder().id(2L).name("Jan").build()
)
);
I want to update one of these objects and I have the following implementation
return findAll().stream()
.filter(s -> s.getId() == studentId)
.map(s -> students.set(students.indexOf(s), Student.builder().id(s.getId()).name(studentPayload.getName()).build()))
.findFirst()
.orElseThrow(() -> new StudentNotFoundException(String.format("Student with id [%d] not found", studentId)));
This returns an object which satisfied with the condition based on filter. Unfortunately this is an not-up-to-date object!
How can I get the updated object after mapping?
Studentobject overrideequals()andhashCode()?