JavaTip : Use set as duplicate remover

1. You fired a query and got results which have duplicates like
List<Category> resultWithDuplicates = getSession().createQuery(“select * from tablename”);

2. Way to remove duplicate is
Set<Category> duplicateRemover  = Sets.newLinkedHashSet(resultWithDuplicates );

3. Can convert set into list by using
resultWithDuplicates = Lists.newArrayList(duplicateRemover);
return categories;


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s