package Gather.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* @author 小王宝友
* @version 3.89
* List集合练习
*/
public class ListExercise {
public static void main(String[] args) {
@SuppressWarnings({"all"})
List list = new ArrayList<>();
for (int i = 0; i < 13; i++) {
list.add("hello"+i);
}
System.out.println("list="+list);
//在2号位插入一个元素
list.add(1,"city");
System.out.println("list="+list);
//获得第五个元素
System.out.println("第五个元素为:"+list.get(4));
//删除第六个元素
list.remove(5);
System.out.println("list="+list);
//修改第七个元素
list.set(6,"乌拉!");
System.out.println("list="+list);
Iterator iterator = list.iterator();
while (iterator.hasNext()) {
Object object = iterator.next();
System.out.println("object="+object);
}
}
}