src/java.base/share/classes/java/lang/String.java
changeset 52682 c93e62e7fa3c
parent 52312 5b9c8d77a9fe
child 52914 4fa75d8ad418
--- a/src/java.base/share/classes/java/lang/String.java	Mon Nov 26 09:46:20 2018 -0500
+++ b/src/java.base/share/classes/java/lang/String.java	Mon Nov 26 12:20:06 2018 -0400
@@ -37,6 +37,7 @@
 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;
@@ -2973,6 +2974,25 @@
     }
 
     /**
+     * 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.
      *
      * @return  the string itself.