The Java Tutorials - String
Using String's static format() method allows you to create a formatted string that you can reuse, as opposed to a one-time print statement. For example, instead of
System.out.printf("The value of the float variable is %f, while the value of the " +
"integer variable is %d, and the string is %s", floatVar, intVar, stringVar);
you can write
String fs;
fs = String.format("The value of the float variable is %f, while the value of the " +
"integer variable is %d, and the string is %s", floatVar, intVar, stringVar);
System.out.println(fs);
peter_budo
Code tags enforcer
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
That method is pretty similar to the printf() method of String. What you could also do is, if you only have a couple of things, you could tab them, ie:
System.out.println( "Blah\tBlah" ); would give you an output like:
Blah Blah
mickinator
Junior Poster in Training
55 posts since Oct 2007
Reputation Points: 10
Solved Threads: 5
As long as the first String is always of the same length and does not vary over the "tabStop index" length. printf (if you're using a late enough version of it) is, of course, the proper way to do this.
masijade
Industrious Poster
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494