Java SE API
Function.apply()
Invokes a transformation. Null acceptance and side effects depend on its implementation.
Formal Syntax & Structure
java syntaxjava
R apply(T t)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| t | T | Input value |
Return Value
R
Result of transformation
Working Example
Example Snippetjava
import java.util.*;import java.util.function.*;public class Main {
public static void main(String[] args) { Function<String, String> label = name -> "Item: " + name.trim(); Consumer<String> print = text -> System.out.println(text); Supplier<String> defaultName = () -> "unknown"; print.accept(label.apply(" pencil ")); print.accept(label.apply(defaultName.get())); }}