Padding a String with Zeros in Java

I thought there was a function in Java which pads a string for you, so that string is certain length. I could not find the function but realized that there is a easier and simpler solution, a “while loop”.

e.g.

while ( string.length() < 8){

string = “0″ + string;

}

I am sure there is a better way to do this but if performance is not your concern then this is perfect.

Reblog this post [with Zemanta]



Related posts:

  1. .net ping
  2. PHP & Global Variables
  3. Beware of Differences PHP4 & PHP5

Leave a Reply