37.4.1 Methods appendReplacement and appendTail
The new Matcher
method overloads appendReplacement
(lines 24–25) and appendTail
(line 29) are used with Matcher
method find
(line 23) and a StringBuilder
in a loop to iterate through a String
and replace every-regular expression match with a specified String. At the end of the process, the StringBuilder
contains the original String’s
contents updated with the replacements. Lines 13–26 proceed as follows:
Line 13 creates a
Pattern
to match—in this case, the literal characters"an"
.Line 17 creates ...
Get Java How to Program, Early Objects, 11th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.