此循环插入员工 ID,例如 1、2、4、.. 30。
for(int i=01;i<31;i++){
Employee e = new Employee();
e.setEmpId(i);
aList.add(e);
}
但是,我需要格式为 01、02、03 .. 等的 ID。 有没有一种简单的方法可以实现这一目标?
最佳答案
整数没有格式。它们是数字。字符串有格式。您可以使用 NumberFormat 或 DecimalFormat 格式化数字。
关于java - 从 int 获取 01 而不是 for 循环中的 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18361301/