Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how many characters in \n JAVA?

Tags:

java

just a quick question.

I wonder how many characters count for \n (new line ) in JAVA?

Because I need to fit 160 chars in one String,etc.

So.. How many chars should I consider for \n when appending to my StringBuffer?

Thanks

like image 710
kitokid Avatar asked Jun 13 '11 03:06

kitokid


1 Answers

'\n' itself is one character when represented internally in Java, but when interfacing with external systems it can be represented by anywhere between 1 and 8 bytes. Some systems and protocols represent a newline with \r\n, which is 2 characters. And the encoding matters as well, since it can cause each character to use 1, 2, or 4 bytes.

Without more information on what system or protocol the characters are going to be sent on it is not possible to give a completely accurate answer.

like image 80
Ignacio Vazquez-Abrams Avatar answered Sep 23 '22 06:09

Ignacio Vazquez-Abrams