Java 13 Triple-quote Text Block *WITHOUT* newlines

You can use String.lines introduced since Java-11 as:

String output = paragraph.lines().collect(Collectors.joining());

A complimentary and for what's worth it, here is a screenshot from JShell execution of the two different blocks of code:

enter image description here


The designers of this feature realized this requirement as well (see 'New escape sequences' in JEP368). So, with the latest early access build for JDK 14 you can use a trailing \ to escape the new line at the end of a line:

public class Main {
    public static void main(String[] args) {
        String paragraph =
            """
            aaaa bbbb cccc \
            dddd eeee ffff \
            gggg hhhh iiii \
            """;
        System.out.println(paragraph);
    }
}

Prints:

aaaa bbbb cccc dddd eeee ffff gggg hhhh iiii