This is the third solution to remove the duplicate numbers from an Array of integers. This program uses distinct method of Stream in the Arrays.
import java.util.Arrays;
public class DuplicateNumbersRemovalUsingStream {
public static void main(String[] args) {
//Array of integers in unsorted order
int [] arrNums= {23,44,13,754,128,23,200,44};
System.out.println("The original Array given below");
//Using stream method of Arrays to display
Arrays.stream(arrNums).forEach(x->System.out.print(x+" "));
//Usage of Distinct method removed all the duplicate numbers.
System.out.println("\nSame Array after removing the duplicate numbers is below");
Arrays.stream(arrNums).distinct().forEach(x->System.out.print(x+" "));
}
}
OUTPUT-
The original Array given below
23 44 13 754 128 23 200 44
Same Array after removing the duplicate numbers is below
23 44 13 754 128 200

Leave a comment