new data:
ArrayList<Comment> newComments = getComments();
already existing data, has some data already filled in:
ArrayList<Comment> oldComments
I can’t overwrite entire old contents with new ones.
I want new (not already present) Comment objects in newComments to be added to oldComments, also I want those missing in newComments to be removed from oldComments.
Is there some good method in Collections package for this ? or any other way ?
NOTE: Comment class has custom compare() method (not using default equals() )
A
java.util.Setis more appropriate for your use case. Then you can do: