+ 1

What is the difference of \n and \r in Java?

Since both function is new line, what is the difference? and give example scenario of use.

12th Jul 2019, 7:19 PM
Neth
Neth - avatar
3 Answers
+ 3
Just want to add that you should use System.lineSeparator() to keep the code platform independent. Cheers ^^
12th Jul 2019, 8:00 PM
Tashi N
Tashi N - avatar
0
No. \n for linux \r\n for windows
12th Jul 2019, 7:46 PM
itsQuasar✅
itsQuasar✅ - avatar
0
\n works on windows too when you print something on screen, \r\n you get when you read text from files. \r \n are ascii code chars, in printer commands \n turn printer roller and feed paper about one line, \r move printer head to start position at begin of line.
13th Jul 2019, 6:05 AM
zemiak