Java Utililty Methods String Pad Zero

List of utility methods to do String Pad Zero

Description

The list of methods to do String Pad Zero are organized into topic(s).

Method

StringzeroPad(String string, int digits)
zero Pad
while (string.length() < digits)
    string = "0" + string;
return string;
StringzeroPadAfterTo(String hex, int i)
zero Pad After To
if (hex.length() == i) {
    return hex;
} else if (hex.length() > i) {
    throw new AssertionError();
StringBuilder sb = new StringBuilder();
for (int j = 0; j < i - hex.length(); j++) {
    sb.append('0');
...
StringzeroPadding(String str, int len)
Converts the string to "zero-padded" string
StringBuffer buffer = new StringBuffer(str);
for (int i = 0; i < len - str.length(); i++) {
    buffer.insert(0, '0');
return buffer.toString();
StringzeroPadding(String value, int n)
zero Padding
if (value.length() > n)
    return value;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n - value.length(); i++) {
    sb.append("0");
sb.append(value);
return sb.toString();
...
StringzeroPadLeft(String s, final int len)
zero Pad Left
s = s.trim();
if (s.length() > len) {
    return s;
int fll = len - s.length();
final char[] charArray = new char[len];
int index = 0, res = fll / 65;
while (res > 0) {
...
StringzeropadRight(String s, int len)
zeropad Right
StringBuilder d = new StringBuilder(s);
while (d.length() < len)
    d.append('0');
return d.toString();
StringzeroPadSSN(String ssn)
zero Pad SSN
int ssnInt = Integer.parseInt(ssn);
return String.format("%09d", ssnInt);
StringzeroPadString(String string, int length)
Pads the supplied String with 0's to the specified length and returns the result as a new String.
StringBuffer buf = new StringBuffer(length);
buf.append(zeroArray, 0, length - string.length()).append(string);
return buf.toString();
StringzeroPadString(String string, int length)
Pads the supplied String with 0's to the specified length and returns the result as a new String.
if (string == null || string.length() > length) {
    return string;
StringBuilder buf = new StringBuilder(length);
buf.append(zeroArray, 0, length - string.length()).append(string);
return buf.toString();
StringzeroPadString(String string, int length)
zero Pad String
if (string == null || string.length() > length) {
    return string;
StringBuilder buf = new StringBuilder(length);
buf.append(zeroArray, 0, length - string.length()).append(string);
return buf.toString();