Govt Exams
In option C, you cannot specify types in lambda parameters when using implicit typing. It should be either (x, y) or explicitly define all parameters.
Optional is used to handle absence of values gracefully. Methods like ifPresent(lambda) and orElse() help prevent null pointer exceptions.
Function<Integer, Integer> takes an Integer and returns an Integer. f.apply(5) computes 5 * 5 = 25.
The map() with lambda x -> x * 2 doubles each element: 1*2=2, 2*2=4, 3*2=6, 4*2=8, resulting in [2, 4, 6, 8].
Supplier<T> is a functional interface with method get() that takes no parameters and returns a value of type T.
forEach with the lambda expression n -> System.out.println(n) iterates through each element and prints it with a newline.
The map() method in Stream API returns a new Stream with transformed elements of type R, maintaining the stream pipeline.
Lambda expressions can only access local variables that are final or effectively final to ensure thread safety and immutability.
Compiler uses target type (functional interface) to infer parameter types. If context is clear, explicit types not needed: list.forEach(x -> ...).
filter() method in streams takes Predicate which tests condition and returns boolean to determine if element should be included.