206. Where are the built–in functional interfaces commonly
used?
Answer:
Java 8 has added the Stream API that helps to perform bulk
operations on Collections. The built-in
functional interfaces are
commonly used as parameters to the methods in the stream API.
The Stream methods apply the
operation specified by the
functional interface to each element in the Stream. For example,
the Stream interface has a filter method
that filters a Collection
based on some condition. The condition is specified via the
Predicate interface which is an in-built functional interface. It
checks if each value in the input
Stream matches the condition
specified by the Predicate. Similarly,
the Stream interface has a
method called map that transforms the elements in a Stream. It
accepts as parameter a Function instance which is an in-built
functional interface. It applies the operation specified by the
Function interface to each element in the Stream.