ArrayList<Integer> arr = new ArrayList<>();
arr.add(1);
对于该集合用增强应该如何遍历,下面方法有何区别呢
for (Integer a : arr) {
System.out.print(a + " ");
}
for (int a : arr) {
System.out.print(a + " ");
}
arr.add(1);
对于该集合用增强应该如何遍历,下面方法有何区别呢
for (Integer a : arr) {
System.out.print(a + " ");
}
for (int a : arr) {
System.out.print(a + " ");
}
Integer和int的转换是个一个拆箱装箱的概念,如果不理解可以自己百度或谷歌脑补一下