IntStream distinct() in Java with examples Last Updated : 06 Dec, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report IntStream distinct() is a method in java.util.stream.IntStream. This method returns a stream consisting of the distinct elements. This is a stateful intermediate operation i.e, it may incorporate state from previously seen elements when processing new elements. Syntax : IntStream distinct() Where, IntStream is a sequence of primitive int-valued elements. Below given are some examples to understand the function in a better way. Example 1 : Printing distinct elements of Integer stream. Java // Java code for IntStream distinct() import java.util.*; import java.util.stream.IntStream; class GFG { // Driver code public static void main(String[] args) { // creating a stream IntStream stream = IntStream.of(2, 3, 3, 5, 6, 6, 8); // Displaying only distinct elements // using the distinct() method stream.distinct().forEach(System.out::println); } } Output : 2 3 5 6 8 Example 2 : Counting value of distinct elements in a stream. Java // Java code for IntStream distinct() method // to count the number of distinct // elements in given stream import java.util.*; import java.util.stream.IntStream; class GFG { // Driver code public static void main(String[] args) { // creating a stream IntStream stream = IntStream.of(2, 3, 3, 5, 6, 6, 8); // storing the count of distinct elements // in a variable named total long total = stream.distinct().count(); // displaying the total number of elements System.out.println(total); } } Output : 5 Comment More infoAdvertise with us Next Article IntStream count() in Java with examples S Sahil_Bansall Follow Improve Article Tags : Misc Java Java - util package Java-Functions java-stream java-intstream +2 More Practice Tags : JavaMisc Similar Reads IntStream count() in Java with examples IntStream count() returns the count of elements in the stream. IntStream count() is present in java.util.stream.IntStream Syntax : long count() Example 1 : Count the elements in IntStream. Java // Java code for IntStream count() // to count the number of elements in // given stream import java.util. 2 min read Stream count() method in Java with examples long count() returns the count of elements in the stream. This is a special case of a reduction (A reduction operation takes a sequence of input elements and combines them into a single summary result by repeated application of a combining operation). This is a terminal operation i.e, it may travers 2 min read BigInteger subtract() Method in Java with Examples The java.math.BigInteger.subtract(BigInteger val) is used to calculate the Arithmetic difference of two BigIntegers. This method is applicable on large value numbers of range much greater than the range of biggest data type double of Java without compromising with the precision of the result but as 3 min read Arrays.equals() in Java with Examples The Arrays.equals() method comes under the Arrays class in Java. It is used to check two arrays, whether single-dimensional or multi-dimensional array are equal or not. Example:Below is a simple example that uses Arrays.equals() method to check if two arrays of integers are equal or not.Java// Java 3 min read ArrayList removeIf() Method in Java with Examples The Java ArrayList removeIf() method is used to remove all elements from the ArrayList that satisfy a given predicate filter. The predicate is passed as a parameter to the method, and any runtime exceptions thrown during iteration or by the predicate are passed to the caller.The removeIf() method us 2 min read Double.equals() Method in Java with Examples The Double.equals() in Java is a built-in function from the java.lang.Double class. This method compares the content of two Double objects. The result is true if and only if the argument is not null and is a Double object that contains the same double value as this object. This method is useful for 3 min read Like