As stated in the groovydoc, split
will return an array of string, which doesn't have a lot of groovy enhancements. tokenize
returns a list instead of an array:
def names = "john paul pete"
assert names.tokenize().findResults {
if (it.startsWith("p")) it.capitalize()
}.join(" ") == "Paul Pete"