LongStream count() example

Description

LongStream 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.LongStream;
//  ww w  . ja va  2s . co  m
public class Main {
  public static void main(String[] args) {
    LongStream b = LongStream.of(1L, 2L, Long.MAX_VALUE, Long.MIN_VALUE);
    long o = b.count();
    
    System.out.println(o); 
    
  }
}

The code above generates the following result.





















Home »
  Java Streams »
    Reference »




Collectors
DoubleStream
DoubleStream.Builder
IntStream
IntStream.Builder
LongStream
LongStream.Builder
Stream
Stream.Builder