Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String formatting in JDK 1.4.2

 
Raksha Shetty
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I need to format Strings to be of a certain width. Could anyone suggest any in-built methods for this?
I've seen some String.format() method stuff but it doesn't seem to exist in JDK 1.4; only JDK1.5 and above.
There's surely gotta be a better way than, say, tabbing !?

Thanks,
Raksha
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check for third-party libraries, otherwise it's pretty trivial to write your own left- and right-padding methods. And welcome to JavaRanch!
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
string.format will make your life more busy in coding
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
shanky sohar wrote:string.format will make your life more busy in coding

That's only available in Java 1.5 onwards, which is why he's asking the question.
 
Raksha Shetty
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the responses ..
I have created my own little padding function to solve the formatting issue.

Now I face another issue, which is that the text that I have padded appears perfectly in some settings and is all misaligned in certain other settings of the browser.

Any way I can make this small piece of code robust enough to handle all these browser settings problems?

Thanks again!
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Padding etc. on the *browser* should be handled via CSS and the DOM, not on the Java side.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic