Friday, February 10, 2017

WAP to find out duplicate value all duplication in Array

import java.util.HashSet;
class DuplicateNumberArray2
{
public static void main(String[] args)
    {
        String[] arr = {"xyz", "def", "mno", "xyz", "pqr", "xyz", "def"};
HashSet<String> hs=new HashSet<String>(); //HashSet does not allow duplicate Value
System.out.println("All Duplicate Elements are :");
        for (String s:arr)
        {
       if(hs.add(s)==false) //Duplicate value will not insert & return false
                System.out.println(s);            
        }
}
}

Share this

0 Comment to " WAP to find out duplicate value all duplication in Array"

Post a Comment