Govt. Exams
Entrance Exams
All three are valid lambda expression syntaxes with different parameter types and return statements.
map() is the intermediate operation used to transform elements from one type/value to another. It applies a function to each element.
@FunctionalInterface is a compile-time check that ensures an interface has exactly one abstract method, making it safe for lambda implementation.
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.
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.