The moose likes Beginning Java and the fly likes System.out.println Special Characters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "System.out.println Special Characters" Watch "System.out.println Special Characters" New topic

System.out.println Special Characters

David Dickinson
Ranch Hand

Joined: Nov 11, 2004
Posts: 66

Does the command System.out.println have any special functions which enter tabs into the stream or anything like that? Features which would improve the formatting of the console output?

For instance I have multiple lines and wish for the information to be displayed like so..

Report xyz calculates currency exchange �-$ = $120
Report xyz calculates oil price rise to be = $110/day

Etc etc so the equals column is always level
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24195

You can embed a tab in a string using the escape sequence \t -- i.e.,


prints a tab character.

[Jess in Action][AskingGoodQuestions]
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
System.out.println( "oil price" + '\t' + "$50" );
System.out.println( "wine price" + '\t' + "$60" );

Be aware that the number of spaces between tabs could be 5, so hitting the same tab to align columns requires a bit of planning.

Mike Gershman
SCJP 1.4, SCWCD in process
I agree. Here's the link:
subject: System.out.println Special Characters
It's not a secret anymore!