package cn.stat.p3.conection.demo; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; public class conectionDemo { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Collection cl=new ArrayList(); show(cl); } public static void show(Collection col) { col.add("aaa"); col.add("bbb"); col.add("ccc"); System.out.println(col); Iterator it=col.iterator(); while(it.hasNext()) { System.out.println(it.next()); } } }
package cn.stat.p4.list.demo; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.LinkedList; public class listDemo { public static void main(String[] args) { // TODO 自动生成的方法存根 LinkedList<String> nlist=new LinkedList<String>(); show(nlist); } private static void show(LinkedList nlist) { // TODO 自动生成的方法存根 nlist.add("aaa"); nlist.add("bbb"); nlist.add("ccc"); System.out.println(nlist); nlist.add(1,"ddd"); System.out.println(nlist); ListIterator it=nlist.listIterator(); while(it.hasNext()) { Object obj=it.next(); if(obj.equals("bbb")) { it.add("qqq"); } }System.out.println(nlist); System.out.println(it.previous()); System.out.println(it.previous()); System.out.println(it.previous()); /* System.out.println(nlist); System.out.println("remove="+nlist.remove(2)); nlist.set(2, "qqq"); System.out.println(); System.out.println(nlist.get(2)); */ } public listDemo() { super(); // TODO 自动生成的构造函数存根 } }
时间: 2024-10-11 18:33:49