Java Streams - IntStream count() example








IntStream count() returns the count of elements in this stream.

Syntax

count has the following syntax.

long count()

Example

The following example shows how to use count.

import java.util.stream.IntStream;

public class Main {
  public static void main(String[] args) {
    IntStream i = IntStream.of(6,5,7,1, 2, 3, 3);
    long d = i.count();
    System.out.println(d);
  }
}

The code above generates the following result.