by @saigowthamr

How to create a multiline string in Java

Home » java » How to create a multiline string in Java

To create a multiline string in Java, we can use the join() method by passing /n as a first argument.

Here is an example:

public class Main
{
   public static void main(String[] args) {


   String s = String.join("\n",
           "This is the way we can",
           "create a multiline string",
           "in java"
         );

   System.out.println(s);
  }
}

Output:

This is the way we can
create a multiline string
in java