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 6: You have been given below code, what is the behavior expected?

Question 6: You have been given below code, what is the behavior expected?

package com.hadoopexam;

import java.util.Arrays;

import java.util.List;

import java.util.function.Predicate;

public class Welcome {

public static void main(String[] args) {

List<String> allSites = Arrays.asList("HadoopExam", "QuickTechie", "Training4Exam");

Predicate<String> predicate = site -> {

System.out.println("Watching Hadoop Training Course ...");

return site.contains("Hadoop");

};

allSites.stream().filter(siteName -> siteName.length() > 3).allMatch(predicate);

}

}

1. It will print  Watching Hadoop Training Course ...

2. It will print 

Watching Hadoop Training Course ...

Watching Hadoop Training Course ...

3. It will print 

Watching Hadoop Training Course ...

Watching Hadoop Training Course ...

Watching Hadoop Training Course ...

4. There will be a compile time error.

Correct Answer : 2 Exp : allMatch will check for the element until it return true or you can say until it find first false.

In this code, it will check siteName contains "Hadoop" word in string for "HadoopExam"  its true , hence print statement. Next will check for second string "QuickTechie" its false , by that time print statement executed. Hence, allMatch will stop here. So its checking only two times.

boolean java.util.stream.Stream.allMatch(Predicate<? super String> predicate)

Returns whether all elements of this stream match the provided predicate. May not evaluate the predicate on all elements if not necessary for determining the result. If the stream is empty then true is returned and the predicate is not evaluated. 

This is a short-circuiting terminal operation.

Parameters:

predicate a non-interfering, stateless predicate to apply to elements of this stream

Returns:

true if either all elements of the stream match the provided predicate or the stream is empty, otherwise false

@apiNote

This method evaluates the universal quantification of the predicate over the elements of the stream (for all x P(x)). If the stream is empty, the quantification is said to be vacuously satisfied and is always true (regardless of P(x)).

 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 6: You have been given below code, what is the behavior expected?