Correct Answer : Get Lastest Questions and Answer : Explanation: sites.forEach(allSite -> System.out.print(allSite + " ")); Above line will print each element from list.
Below line , filter each element from list. It will consider only element which has i in it.
public class Welcome { public static void main(String[] args) { List sites = Arrays.asList("HadoopExam.com", "Training4Exam.com", "QuickTechie.com"); Function funVal = s -> " Welcome to : ".concat(s); sites.stream().map(funVal).peek(System.out::print); } } 1. It will print Welcome to : HadoopExam.com Welcome to : Training4Exam.com Welcome to : QuickTechie.com
2. It will print HadoopExam.com: Training4Exam.com: QuickTechie.com
Correct Answer : Get Lastest Questions and Answer : Explanation: Stream operations and pipelines Stream operations are divided into intermediate and terminal operations, and are combined to form stream pipelines. A stream pipeline consists of a source (such as a Collection, an array, a generator function, or an I/O channel); followed by zero or more intermediate operations such as Stream.filter or Stream.map; and a terminal operation such as Stream.forEach or Stream.reduce. Intermediate operations return a new stream. They are always lazy; executing an intermediate operation such as filter() does not actually perform any filtering, but instead creates a new stream that, when traversed, contains the elements of the initial stream that match the given predicate. Traversal of the pipeline source does not begin until the terminal operation of the pipeline is executed. Terminal operations, such as Stream.forEach or IntStream.sum, may traverse the stream to produce a result or a side-effect. After the terminal operation is performed, the stream pipeline is considered consumed, and can no longer be used; if you need to traverse the same data source again, you must return to the data source to get a new stream. In almost all cases, terminal operations are eager, completing their traversal of the data source and processing of the pipeline before returning. Only the terminal operations iterator() and spliterator() are not; these are provided as an "escape hatch" to enable arbitrary client-controlled pipeline traversals in the event that the existing operations are not sufficient to the task. Processing streams lazily allows for significant efficiencies; in a pipeline such as the filter-map-sum example above, filtering, mapping, and summing can be fused into a single pass on the data, with minimal intermediate state. Laziness also allows avoiding examining all the data when it is not necessary; for operations such as "find the first string longer than 1000 characters", it is only necessary to examine just enough strings to find one that has the desired characteristics without examining all of the strings available from the source. (This behavior becomes even more important when the input stream is infinite and not merely large.) Intermediate operations are further divided into stateless and stateful operations. Stateless operations, such as filter and map, retain no state from previously seen element when processing a new element -- each element can be processed independently of operations on other elements. Stateful operations, such as distinct and sorted, may incorporate state from previously seen elements when processing new elements. Stateful operations may need to process the entire input before producing a result. For example, one cannot produce any results from sorting a stream until one has seen all elements of the stream. As a result, under parallel computation, some pipelines containing stateful intermediate operations may require multiple passes on the data or may need to buffer significant data. Pipelines containing exclusively stateless intermediate operations can be processed in a single pass, whether sequential or parallel, with minimal data buffering. Further, some operations are deemed short-circuiting operations. An intermediate operation is short-circuiting if, when presented with infinite input, it may produce a finite stream as a result. A terminal operation is short-circuiting if, when presented with infinite input, it may terminate in finite time. Having a short-circuiting operation in the pipeline is a necessary, but not sufficient, condition for the processing of an infinite stream to terminate normally in finite time.
Question : You have been given below interface
package com.hadoopexam;
public interface Welcome {
public default void call(Integer distance) { System.out.println("Welcome to HadoopExam Learning Resources"); }
public void run(Integer distance); }
Which is the valid use of Welcome interface? 1. Welcome courseCount = n -> System.out.println("Start watching Hadoop Training " + n); courseCount.run(1); courseCount.call(2);
2. Welcome courseCount = n ->n + 10; courseCount.run(1); courseCount.call(2);
4. Welcome is not correctly declare to be used in a lambda expression.
Correct Answer : Get Lastest Questions and Answer : Explanation: : It's a simple lambda expression in option 1. Option 3 is clearly wrong, call method is not static.
In option 2 , you are trying to return a value n+2, however it is not expected as per the Welcome class method.