Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sprintf type string formatting in java

Status
Not open for further replies.

hargate

Programmer
Feb 10, 2001
2
US
I am trying to display information on a users xterm in table form. To do this in c/c++ I would format the strings that I output to the screen with sprintf/printf.

How do I specify the field width in the format string for a MessageFormat object like sprintf?

Object[] fields = {"field1", "field2", "field3"};
System.out.println( new MessageFormat( "{0} {1} {2}", fields);
 
Just to let people know what I have discovered:

You cannot accomplish printf style formatting with the
the MessageFormat object. There is a class available
on the java.sun.com site called PrintfFormat that supports printf style formatting.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top