What about %n
using a formatter like String.format()
?:
String s = String.format("I%nam%na%nboy");
As this answer says, its available from java 1.5 and is another way to System.getProperty("line.separator")
or System.lineSeparator()
and, like this two, is OS independent.