Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > How can I write right-justified into a 12 chars width field?

Thread Tools

How can I write right-justified into a 12 chars width field?

Catherina Svensson
Posts: n/a
Lets say I have a String var which can contain values of different lengths e.g.
"aaa" or "bb bb bb".

I want to print them out with System.out.println right-justified with a field width
of 12 chars. If necessary this field should be left padded with blanks.
For the samples above the output should be e.g.:

" aaa"
" bb bb bb"

How can I implement this right-justified, blank padded, fixed-width filed output in Java?


Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How to truncate char string fromt beginning and replace chars instring by other chars in C or C++? Hongyu C++ 9 08-08-2008 12:18 PM
Textbox width scaling to width of data not width of page? AndrewF ASP .Net 1 10-10-2005 04:38 PM
Floats to chars and chars to floats Kosio C Programming 44 09-23-2005 09:49 AM
receiving ??? chars instead of "special" chars M.Posseth ASP .Net Web Services 3 11-16-2004 07:00 PM