How to remove all duplicates from an array of integers in Java using Java 8
Categories: Java 8(JDK1.8) Java Java Examples
package r4r.co.in;
import java.util.Arrays;
import java.util.stream.Stream;
public class RemoveAllDuplicateInteger {
public static void main(String[] args) {
//How to remove all duplicates from an array of integers in Java using Java 8
Integer [] input= {1,2,3,6,1,9,3,7,3,7,8,3,4,5,6};
Integer[] output=Stream.of(input).distinct().toArray(Integer[]::new);
System.out.print(Arrays.toString(output));
}
}
OutPut:- [1, 2, 3, 6, 9, 7, 8, 4, 5]