How to append a newline to StringBuilder

To append a newline to a StringBuilder object in Java, you can use the append method and pass it a newline character. Here's an example:

StringBuilder sb = new StringBuilder();
sb.append("Hello");
sb.append('\n');
sb.append("World");

System.out.println(sb.toString());

This will output the following string:

Hello
World