Stream count()
returns the count of elements in this stream.
count
has the following syntax.
long count()
The following example shows how to use count
.
import java.util.Arrays; import java.util.List; /*from w ww.j a va 2 s . co m*/ public class Main { public static void main(String[] args) { List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5); long o = numbers.stream() .count(); System.out.println(o); } }
The code above generates the following result.