Here you can find the source of zeroPad(String s, int length)
Parameter | Description |
---|---|
s | String to pad. |
length | Length to pad to. |
public static String zeroPad(String s, int length)
//package com.java2s; /* Please see the license information at the end of this file. */ public class Main { /**//from w ww . j a v a 2 s.c om * Pad string with leading zeros. * * @param s * String to pad. * @param length * Length to pad to. * * @return Input string left-padded with '0' characters to specified length. */ public static String zeroPad(String s, int length) { for (int i = s.length(); i < length; i++) { s = "0" + s; } return s; } }