Multiline String in Java

Problem

Given the following text with multiple lines:

abc
def

How to assign this text to a String by keeping the formatting on multiple lines in the Java code?

Solution

Java 13 and above

var s = """
        abc
        def
        """;

Java 6 and above

String s = "abc\n"
         + "def\n";