Remove duplicate entries in a Vector in java

One of the solution which normally every java developer faced once.We have to remove the duplicate
value from a vector in java.

There are two solution for it one.

1.

Vector newVect = new Vector(new LinkedHashSet(originalVect));


or this, if you do not need a new Vector object created

2

Collection noDup = new LinkedHashSet(vectorContainingDup);
vectorContainingDup.clear();
vectorContainingDup.addAll(noDup);

In both cases we puting duplicate vector in linkedHashSet , which will remove the duplicate values.

Enjoy coding 🙂 with techartifact………………………….

Vinay

I am an Oracle ACE in Oracle ADF/Webcenter. Sr Java Consultant-working on Java/J2EE/Oracle ADF/Webcenter Portal/ content and Hibernate for several years. I'm an active member of the OTN JDeveloper/Webcenter forum. Passionate about learning new technologies. I am here to share my knowledge. Give your views and suggestion on [email protected] .

More Posts - Website

Follow Me:
TwitterLinkedInGoogle PlusYouTube