Java Reference
In-Depth Information
Table 3-1. String escapes
To get:
Use:
Notes
Tab
\t
Linefeed (Unix
newline)
The call System.getProperty("line.separator") will give you the platform's
line end.
\n
Carriage return
\r
Form feed
\f
Backspace
\b
Single quote
\ '
Double quote
\ "
Unicode character
Four hexadecimal digits (no \x as in C/C++). See http://www.unicode.org for
codes.
\u
NNNN
Octal(!) character
Who uses octal (base 8) these days?
\ NNN
Backslash
\\
Here is a code example that shows most of these in action:
public
public class
class StringEscapes
StringEscapes {
public
public static
void main ( String [] argv ) {
System . out . println ( "Java Strings in action:" );
// System.out.println("An alarm or alert: \a"); // not supported
System . out . println ( "An alarm entered in Octal: \007" );
System . out . println ( "A tab key: \t(what comes after)" );
System . out . println ( "A newline: \n(what comes after)" );
System . out . println ( "A UniCode character: \u0207" );
System . out . println ( "A backslash character: \\" );
static void
}
}
If you have a lot of non-ASCII characters to enter, you may wish to consider using Java's in-
put methods, discussed briefly in the JDK online documentation.
Search WWH ::




Custom Search