import java.util.ArrayList;
import java.util.Iterator;
public class ArrayListTest {
public static void main(String[] args) {
ArrayList<Integer> myList = new ArrayList<Integer>();
myList.add(1);
myList.add(9);
myList.add(9);
myList.add(7);
myList.add(0);
myList.add(2);
myList.add(1);
myList.add(4);
for(Integer num:myList) {
System.out.print(num);
}
System.out.println();
myList.set(1, 2);
for(int i=0;i<myList.size();i++) {
System.out.print(myList.get(i));
}
System.out.println();
myList.remove(0);
Iterator<Integer> it = myList.iterator();
while(it.hasNext()) {
System.out.print(it.next());
}
}
}
原文地址:https://www.cnblogs.com/wumingoo1/p/10317567.html
时间: 2024-11-06 09:35:09