Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

line.separator vs println()

 
Janeice DelVecchio
Saloon Keeper
Posts: 1809
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Does this buy you something that just calling println() won't get you?


Thanks,
Janeice
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nope. the println() method of the PrintStream class forwards to the newLine() method of BufferedWriter, which retrieves the value of the line.separator system property.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50226
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It will allow you to inspect the line.separator String, see how many characters it contains, etc. If I remember correctly it is (char)0xa no *nix and newer Macs, (char)0xd(char)0xa on DOS/Windows and (char)0xd on older Macs.
 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:If I remember correctly it is (char)0xa no *nix and newer Macs, (char)0xd(char)0xa on DOS/Windows and (char)0xd on older Macs.

Or simply \n on *nix (Unix, Linux, etc) and newer Macs, \r\n on DOS/Windows and \r on older Macs. Yes they are the same characters, but aren't \r and \n easier to read than (char)0xd and (char)0xa, or even (char)13 and (char)10?
 
Janeice DelVecchio
Saloon Keeper
Posts: 1809
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
 
Campbell Ritchie
Sheriff
Pie
Posts: 50226
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, but people might not know that \r is (char)0xd.
 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would they need to? And if so, I have www.asciitable.com for that information
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic