I having a problem with coding this:
Write a static method named removeDuplicates that takes as input an array of integers and returns as a result a new
You can use HashSet that does not allow dulplicate elements
public static void deleteDups(int a []) {
HashSet numbers = new HashSet();
for(int n : a)
{
numbers.add(n);
}
for(int k : numbers)
{
System.out.println(k);
}
System.out.println(numbers);
}
public static void main(String[] args) {
int a[]={2,3,3,4,4,5,6};
RemoveDuplicate.deleteDups(a);
}
}
o/p is 2
3
4
5
6
[2, 3, 4, 5, 6]