Using Java's String.format
and System.out.printf
, both \n
and %n
provide a newline. Which one should I use and in which situation?
Asked
Active
Viewed 92 times
3

krystah
- 3,587
- 2
- 25
- 43
-
5`%n` is the **platform-specific** line separator. – Oliver Charlesworth Apr 13 '14 at 11:56
-
2Related: [What's up with Java's “%n” in printf?](http://stackoverflow.com/questions/1883345/whats-up-with-javas-n-in-printf) – PakkuDon Apr 13 '14 at 11:57
-
@OliCharlesworth: that should be an answer. – JB Nizet Apr 13 '14 at 11:57
-
2@PakkuDon: This is basically a duplicate of that... – Oliver Charlesworth Apr 13 '14 at 11:58