I have an arraylist of Comments, which each comment has a specific id and content. I have a modifiedComment with the same id, but with different content, how would I replace it in the comments array? Here is what I tried, I get the comment out, update the content, but don't know how to put it back into the array... The comment class has id and content as attributes.
ArrayList<Comment> comments = foundQuestion.getComments();
// found a comment with specific id
Comment foundComment = comments.stream().filter(comment1 -> comment1.getId().equals(modifiedComment.getId())).collect(Collectors.toList()).get(0);
// update the content of the current comment
foundComment.setContent(modifiedComment.getContent());
I would really appreciate any help.
Commentthat has an identifier but no content, and a collection ofDraftobjects with their own identifier and holding content, children that belong to aCommentparent. The latestDraftchild object is the current content for the parentComment.