int读0000时显示为0,谢了下面一个转换的小程序:
public class num { public String getNumber(int num) { String result = ""; switch ((num+"").length()) { case 1: result = "000" + num; break; case 2: result = "00" + num; break; case 3: result = "0" + num; break; case 4: result = "" + num; break; // 此处代表编号已经超过了9999,从0重新开始 default: result = "0000"; break; } return result; } }
ArrayList<String> list = new ArrayList<String>(); for (int i = 1; i <= 9999; i++) { if (String.valueOf(i).length()==1) { list.add("000"+i); }else if (String.valueOf(i).length()==2){ list.add("00"+i); }else if (String.valueOf(i).length()==3){ list.add("0"+i); }else{ list.add(String.valueOf(i)); } }