I need to delete a comment from a Set<Commentaries>
. And it worked! But I try with the code below, it doesn't work.
After I ordered my Set
by using a TreeSet
with MyComparator
@RequestMapping("/user/editPage/{idContractor}")
public String goToEditPage(@PathVariable("idContractor") Integer idContractor, Model model) {
.....
Set<Commentaries> comSet = contractorsWithId.getCommentarieses();
TreeSet<Commentaries> treeComment = new TreeSet<Commentaries>(new MyComparator());
treeComment.addAll(comSet);
contractorsWithId.setCommentarieses(treeComment);
return "user/editPage";
}
//Below my method for delete
public void removeCommentaries(Commentaries commentToDelete, Contractors contractorWithID) {
contractorWithID.getCommentarieses().remove(commentToDelete);
contractorsService.update(contractorWithID);
}
Help me please! I'm new to stackoverflow and if something you don't understand I can edit my question!
MyComparator
comparing on which field is important.treeComment.addAll(comSet);
The problem with specific code will help.