生成 n 位从 0 开始固定长度的自增长数列

例如:0000 -> 0001 -> 0002 -> 0003 ……

使用 DecimalFormat 对象即可,引自:import java.text.DecimalFormat; 包

public static void main(String args[]){
        
        for(int i=0;i<200;i++) {
            DecimalFormat format = new DecimalFormat("0000");
            System.out.println(format.format(i));
        }
    }

想生成几位,DecimalFormat("000……") 里面放几个零就是几位

原文地址:https://www.cnblogs.com/xuehuashanghe/p/11825682.html