HanuAthena HanuAthena - 3 months ago 9
Java Question

Left padding a String with Zeros

I've seen similar questions here and here.

But am not getting how to left pad a String with Zero.

input: "129018"
output: "0000129018"

The total output length should be TEN.


If your string contains numbers only, you can make it an integer and then do padding:

String.format("%010d", Integer.parseInt(mystring));

If not I would like to know how it can be done.