Govt Exams
Time complexity depends on the specific reduction operation, whether the lambda is stateless, and stream characteristics. Generally O(n), but parallelization overhead affects actual performance.
Without explicit type declarations or context, the compiler must infer types from usage. We can only determine they have a compareTo() method, likely Comparable types.
range(1, 4) generates 1, 2, 3. map(x -> x * x) produces 1, 4, 9. Printed without spaces gives '149'.
Since standard functional interfaces don't declare checked exceptions, you must either wrap in try-catch or create a custom functional interface that throws the checked exception.
peek() is an intermediate operation that returns a stream for chaining, useful for debugging. forEach() is terminal and returns void, ending the stream chain.
filter(x -> x > 2) keeps 3, 4, 5. map(x -> x * 2) transforms them to 6, 8, 10. forEach prints each value.
Method references are compact lambda expressions that directly reference existing methods. They use :: syntax and are equivalent to lambdas that call those methods.
BiFunction<T, U, R> represents a function that accepts two arguments of types T and U, and returns a result of type R.
The lambda expression prints the length of each string. Lengths are 1, 2, and 3 respectively, with spaces between them.
Lambda expressions reduce boilerplate code by allowing inline implementation of functional interfaces without creating anonymous inner classes, enabling a more functional programming style.