What is Shankh???


Shankh is a synonym for Conch Shell.So why that name for this blog?? My grandma used to say "When you put the conch shell to your ear, you hear the sound of ocean". Ignoring all scientific explanations to it, i would like this blog to bring you the sound of vast ocean of technology. Take a look

Some Random quotes


Innovation distinguishes between a leader and a follower. -Steve Jobs

It is not that i am smarter than others, i just persist with problems longer

Remove duplicates from a list in Java

There is a simple way to remove duplicates from Lists, use HashSet or LinkedHashSet. HashSet will not preserve the ordering while LinkedHashSet will preserve it. Here is the sample code

List<String> listWithDuplicates =
   Arrays.asList("to","be","or","not","to","be","that","is","the","question");
List<String> listWithoutDuplicates =
   new ArrayList<String>(new LinkedHashSet<String>(listWithDuplicates));
List<String> listWithoutDuplicatesWithoutOrdering =
   new ArrayList<String>(new HashSet<String>(listWithDuplicates));

Here is the output

List with duplicates:[to, be, or, not, to, be, that, is, the, question]
List with out duplicates:[to, be, or, not, that, is, the, question]
List with out duplicates without ordering:[not, to, that, is, or, question, the, be]

Share

Leave a Reply

Subscribe to Comments?



RECENTPOSTS

MOSTCOMMENTS

MYARCHIVE