If you can't edit the source of the class (why not?), then you need to iterate over the list and compare each item based on the four criteria mentioned ("title, author, url and description").
To do this in a performant way, I would create a new class, something like BlogKey
which contains those four elements and which properly implements equals()
and hashCode()
. You can then iterate over the original list, constructing a BlogKey
for each and adding to a HashMap
:
Map<BlogKey, Blog> map = new HashMap<BlogKey, Blog>();
for (Blog blog : blogs) {
BlogKey key = createKey(blog);
if (!map.containsKey(key)) {
map.put(key, blog);
}
}
Collection<Blog> uniqueBlogs = map.values();
However the far simplest thing is to just edit the original source code of Blog
so that it correctly implements equals()
and hashCode()
.