Tagged: String

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]