printf in Java?

I have several data object with different length and I want to print them nicely in columns. In C++ and C, printf can handle different formatting easily with the formatting char. I'm using a java .library by Horstmann that implements printf.

Since I'm not up-to-date with the latest Java, I'm curious if it has any native utility that handles pretty printing. Any pointer will be appreciated.

Thanks

[422 byte] By [class_is_invalid] at [2007-11-26 12:16:39]
# 1
PrintWriter has a printf statement. Though I admit that I never used it.
CeciNEstPasUnProgrammeur at 2007-7-7 14:53:03 > top of Java-index,Archived Forums,Socket Programming...
# 2

You can use PrintWriter.printf. Java 5 have IMHO great formating capabilities. Look at

http://java.sun.com/j2se/1.5.0/docs/api/java/util/Formatter.html#syntax

E.g. print row 5 space right aligned integer, 20 space left aligned stringSystem.out.printf("|%5d|%-20s|\n", id, name);

Pipes are just table borders, no formating characters.

a3cchan at 2007-7-7 14:53:03 > top of Java-index,Archived Forums,Socket Programming...
# 3
@Op. You can also use String.format if you just want to create a String which yuo want to write to e.g. a database.Kaj
kajbj at 2007-7-7 14:53:03 > top of Java-index,Archived Forums,Socket Programming...
# 4
Or java.util.Formmater if you want to write to: File, OutputStream, Writer, StringBuffer, StringBuilderBut Kajs point on Sting.format was a good one. With varargs format's finally an usefull method. O:-)
a3cchan at 2007-7-7 14:53:03 > top of Java-index,Archived Forums,Socket Programming...
# 5
thanks all, I was looking forward to not using any custom library.
class_is_invalid at 2007-7-7 14:53:03 > top of Java-index,Archived Forums,Socket Programming...