SringSring

Tuesday, 28 October 2014

Find the duplicate entry in the list

package com.srini.collections;

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);
           }
       }
   }
}

No comments:

Post a Comment