www.HadoopExam.com

HadoopExam Learning Resources

Following are the Oracle Java and Oracle SQL Products Provided by HadoopExam Learning Resources
Free Core Java 1Z0-808 Training Java 1Z0-808 Questions and Answers Java 1Z0-809 Questions and Answers Questions for Oracle 1Z0-060 : Upgrade to Oracle Database 12c Administrator Oracle Database 12c: SQL Fundamentals

Question 15: You have been given below code, what is the expected output?

Question 15: You have been given below code, what is the expected output?

package com.hadoopexam;

import java.util.Arrays;

import java.util.List;

class Welcome {

public static void main(String[] args) {

List<Integer> values = Arrays.asList(5,5,5);

values.stream().map(n -> n * 2).peek(System.out::print).count();

}

}

1. It will compile time error

2. It will compile perfectly but give RuntimeError

3. It will compile and run perfectly, but will not produce any output.

4. It will compile and run perfectly, but will produce 555 as output.

5. It will compile and run perfectly, but will produce 101010 as output.

Correct Answer : 5 Exp : Stream<Integer> java.util.stream.Stream.peek(Consumer<? super Integer> action)

Returns a stream consisting of the elements of this stream, additionally performing the provided action on each element as elements are consumed from the resulting stream. 

This is an intermediate operation. 

For parallel stream pipelines, the action may be called at whatever time and in whatever thread the element is made available by the upstream operation. If the action modifies shared state, it is responsible for providing the required synchronization.

Parameters:

action a non-interfering action to perform on the elements as they are consumed from the stream

Returns:

the new stream

long java.util.stream.Stream.count()

Returns the count of elements in this stream. This is a special case of a reduction and is equivalent to: 

return mapToLong(e -> 1L).sum();

This is a terminal operation.

Returns:

the count of elements in this stream

<Integer> Stream<Integer> java.util.stream.Stream.map(Function<? super Integer, ? extends Integer> mapper)

Returns a stream consisting of the results of applying the given function to the elements of this stream. 

This is an intermediate operation.

Parameters:

<R> The element type of the new stream

mapper a non-interfering, stateless function to apply to each element

Returns:

the new stream

Stream<Integer> java.util.Collection.stream()

Returns a sequential Stream with this collection as its source. 

This method should be overridden when the spliterator() method cannot return a spliterator that is IMMUTABLE, CONCURRENT, or late-binding. (See spliterator() for details.)

Returns:

a sequential Stream over the elements in this collection

I have cleared my Java 1Z0-808 Certification exam with 92% using this simulator

I have cleared my Java 1Z0-809 Certification exam with 96% using this simulator

You have no rights to post comments

You are here: Home Oracle Java 1Z0-809 Question 15: You have been given below code, what is the expected output?