Return to site

JAVA CERTIFICATION QUESTION: Stream data filter

=>Filtering a stream returns a stream consisting of the elements of this stream that match the given predicate.

· ocp,java

Given

What is the output?

  • A) 1
  • B) 2
  • C) Compilation fails since we haven't imported predicate.
  • D) Compilation fails due to error at line 7.
  • E) Compilation fails due to error at line 8.

#java #certificationquestion #ocp

 

 

 

 

 

At line 7, we have created a DoubleStream with three doubles.

At line 8 we have used the filter method which lets pass only the values matching values strictly greater than 0.45.

So when count invoked, filter will result a stream with single value.

Hence the number of elements in the stream which count invoked is 1.

·Ɐ ɹǝʍsuɐ sᴉ ɹǝʍsuɐ ʇɔǝɹɹoɔ :uoᴉsnʅɔuoꓛ