Java字符串长度不够前面或后面补0

public static String addZeroForNum(String str, int strLength) {
    int strLen = str.length();
    StringBuffer sb = null;
     while (strLen < strLength) {
           sb = new StringBuffer();
           sb.append("0").append(str);// 左补0
        // sb.append(str).append("0");//右补0
           str = sb.toString();
           strLen = str.length();
     }
    return str;
}

你可能感兴趣的:(Java字符串长度不够前面或后面补0)