add \n after substring java code example Example: how to print \n in a string in java System.out.println("\\n hello world"); // output: // "\n hello world"