将整数转换成固定格式的字符串

 public static String getNumberString(int num)
    {
        char[] numChar = String.valueOf(num).toCharArray();
        if (numChar.length == 12)
        {
            return String.valueOf(numChar);
        }

        char[] retCharArr = new char[12];
        Arrays.fill(retCharArr, '0');
        System.arraycopy(numChar, 0, retCharArr, 12 - numChar.length, numChar.length);
        return String.valueOf(retCharArr);
    }

你可能感兴趣的:(字符串)