Junior — Middle
Can you list the main built-in functional interfaces in standard libraries?
sobes.tech AI
Answer from AI
The standard library in Java includes several built-in functional interfaces that are widely used with lambda expressions and Stream API:
- Function<T, R> — takes an object of type T and returns an object of type R.
- Consumer<T> — takes an object of type T and returns nothing (used for operations with side effects).
- Supplier<T> — takes no arguments and returns an object of type T.
- Predicate<T> — takes an object of type T and returns a boolean, usually for condition checks.
- UnaryOperator<T> — a subtype of Function, takes and returns an object of the same type T.
- BinaryOperator<T> — a subtype of BiFunction, takes two objects of type T and returns an object of type T.
These interfaces allow writing more expressive and concise code, especially when working with collections and data streams.