String.format

String.format("%09d",50)

%d:整形

09:9位,不足补0

private static String template = "%09d";
    private static int[] grids = new int[] {3,2,2,2};
    private static int length = 9;
    
    public static String getAvatar(long key) {
        String r = String.format(template, key);
        StringBuffer buf = new StringBuffer(32);
        
        int pos = 0;
        for (int t: grids) {
            buf.append(r.substring(pos, pos + t));
            pos += t;
            if (pos < length) {
                buf.append('/');
            }
        }
        return buf.toString();
    }

/000/00/00/50

原文地址:https://www.cnblogs.com/yangfei-beijing/p/7991502.html