11:00 pm - Thursday February 23, 2017

To find duplicate value from a Treeset.

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

This tutorial explains how  to find duplicate from  TreeSet.

The easiest way to find duplicate entries from the given array is, create TreeSet object and add array entries to the TreeSet.

Since the set doesnot support duplicate entries, you can easily findout duplicate entries.

Example

import java.util.TreeSet;

public class MyDuplicateEntry

{

   public static void main(String a[])

{

       String[] strArr = {"one","two","three","four","four","five"};

       TreeSet<String> unique = new TreeSet<String>();

       for(String str:strArr){

           if(!unique.add(str)){

            System.out.println("Duplicate Entry is: "+str);

           }

       }

   }
}            

Output

           Duplicate Entry is: four

BACK

Filed in: Java Examples

Comments are closed.