java中List怎么用,说下过程
1 回答
森栏
TA贡献1810条经验 获得超5个赞
List是一个接口,不能实例化,需要实例化一个ArrayList或者LinkedList
List al = new ArrayList();
//使用add()方法添加元素
al.add("a");
al.add("b");
al.add("c");
al.add("d");
//使用Iterator迭代器遍历出集合的元素并打印
for(Iterator i = al.iterator();i.hasNext(); ){
String str = (String) i.next();
System.out.println(str);
}
添加回答
举报
0/150
提交
取消