Java String Pad Zero zeroPadAfterTo(String hex, int i)

Here you can find the source of zeroPadAfterTo(String hex, int i)

Description

zero Pad After To

License

Open Source License

Declaration

public static String zeroPadAfterTo(String hex, int i) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String zeroPadAfterTo(String hex, int i) {
        if (hex.length() == i) {
            return hex;
        } else if (hex.length() > i) {
            throw new AssertionError();
        }/*from ww  w.ja  v a2s. co  m*/
        StringBuilder sb = new StringBuilder();

        for (int j = 0; j < i - hex.length(); j++) {
            sb.append('0');
        }
        String s = hex + sb.toString();
        if (s.length() != i)
            throw new AssertionError();
        return s;
    }
}

Related

  1. zeropad(String s, int len)
  2. zeropad(String s, int len)
  3. zeroPad(String s, int len)
  4. zeroPad(String s, int length)
  5. zeroPad(String string, int digits)
  6. zeroPadding(String str, int len)
  7. zeroPadding(String value, int n)
  8. zeroPadLeft(String s, final int len)
  9. zeropadRight(String s, int len)