mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8203442: String::transform
Reviewed-by: smarks, sherman, alanb, darcy, forax, rriggs, scolebourne, dholmes, plevart
This commit is contained in:
parent
6d25f18bad
commit
40d4ff864c
2 changed files with 93 additions and 0 deletions
|
@ -37,6 +37,7 @@ import java.util.Locale;
|
|||
import java.util.Objects;
|
||||
import java.util.Spliterator;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
|
@ -2972,6 +2973,25 @@ public final class String
|
|||
return indent(indent > n ? Integer.MIN_VALUE : indent, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method allows the application of a function to {@code this}
|
||||
* string. The function should expect a single String argument
|
||||
* and produce an {@code R} result.
|
||||
*
|
||||
* @param f functional interface to a apply
|
||||
*
|
||||
* @param <R> class of the result
|
||||
*
|
||||
* @return the result of applying the function to this string
|
||||
*
|
||||
* @see java.util.function.Function
|
||||
*
|
||||
* @since 12
|
||||
*/
|
||||
public <R> R transform(Function<? super String, ? extends R> f) {
|
||||
return f.apply(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* This object (which is already a string!) is itself returned.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue