The transform() method

Suppose that a file includes the following text, using [ at the beginning of a new line:

[ Talks - Java11, Amber, CleanCode 
[ Oceans - plastic pollution, human callousness

Now, suppose that you must remove the delimiter, [, used at the beginning of all lines. You can use the transform() method to customize the margin management, adding the String class:

 <R> R transform (Function<String, R> f)

The following is an example that uses the method transform() to remove the custom margin characters from the multiline text:

String stripped = ` 
                     [ Talks - Java11, Amber, CleanCode 
                     [ Oceans - dying, human callousness, plastic 
pollution `.transform({ multiLineText.stream() .map(e -> e.map(String::strip) .map(s -> s.startsWith("[ ") ? s.substring("[ ".length()) : s) .collect(Collectors.joining(" ", "", " ")); });

The next section will include some common cases where using raw string literals over traditional strings will benefit you tremendously.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.31.125