import java.util.HashSet;
class DuplicateNumberArray
{
public static void main(String[] args)
{
int[] arr={1,2,3,1,10,20,30,20,1};
System.out.println("All Duplicate Elements Are : ");
HashSet<Integer> hs =new HashSet<Integer>(); //HashSet does not allow duplicate Value
for(int x:arr)
{
if(hs.add(x)==false) //Duplicate value will not insert & return false
{
System.out.println(x);
}
}
}
}
class DuplicateNumberArray
{
public static void main(String[] args)
{
int[] arr={1,2,3,1,10,20,30,20,1};
System.out.println("All Duplicate Elements Are : ");
HashSet<Integer> hs =new HashSet<Integer>(); //HashSet does not allow duplicate Value
for(int x:arr)
{
if(hs.add(x)==false) //Duplicate value will not insert & return false
{
System.out.println(x);
}
}
}
}
0 Comment to "WAP to find out duplicate value all duplication in Array"
Post a Comment