将这段代码修改正确,并输出结果public class Array_List { public static void main(String[] args) { ArrayList arrayList=new ArrayList(8); for(int i=0;i<8;i++){ arrayList.add(new Integer(i)); } Iterator iterator=arrayList.iterator(); while(iterator.hasNext()){ System.out.print(iterator.next());} System.out.println(); arrayList.add(new Integer(6)); arrayList.add(5,new Integer(7)); arrayList.remove(1); Iterator iterator1=arrayList.iterator(); while(iterator1.hasNext()) { System.out.print(iterator1.next()); }
时间: 2023-08-14 21:03:48 浏览: 92
java代码-定义一个员工信息类Employee,使用ArrayList对员工信息进行添加和显示。
以下是修改后的代码,并输出结果:
```java
import java.util.ArrayList;
import java.util.Iterator;
public class Array_List {
public static void main(String[] args) {
ArrayList<Integer> arrayList = new ArrayList<>(8);
for (int i = 0; i < 8; i++) {
arrayList.add(i);
}
Iterator<Integer> iterator = arrayList.iterator();
while (iterator.hasNext()) {
System.out.print(iterator.next());
}
System.out.println();
arrayList.add(6);
arrayList.add(5, 7);
arrayList.remove(1);
Iterator<Integer> iterator1 = arrayList.iterator();
while (iterator1.hasNext()) {
System.out.print(iterator1.next());
}
}
}
```
输出结果:01234567
0234567
阅读全文