How to create multiline strings using Java text blocks
KW.java
class KW 
{
    @SuppressWarnings("preview")
    public static void main(String[] args) 
    {
        String s1 = """
                Welcome
                to
                Kodingwindow""";
        String s2 = "Welcome\nto\nKodingwindow";
        System.out.println(s1);     //text block string
        System.out.println("———————————————————————");
        System.out.println(s2);     //normal string
        System.out.println("———————————————————————");
        System.out.println(s1==s2);
        System.out.println(s1.equals(s2));
    }
}
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW Welcome to Kodingwindow ——————————————————————— Welcome to Kodingwindow ——————————————————————— true true kodingwindow@kw:~$
What Next?
Java Arrays
Advertisement