- package com.liang;
- import java.util.*;
- public class TestArrayList {
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- ArrayList al=new ArrayList();
- al.add("aaa");
- al.add("aaa");
- al.add("aaa");
- al.add("ccc");
- al.add("ccc");
- al.add("bbb");
- al.add("bbb");
- sop(al);
- System.out.println("----------------------------");
- al=newAl(al);
- sop(al);
-
- }
- public static ArrayList newAl(ArrayList list){
- ArrayList newlist=new ArrayList();
-
- Iterator it=list.iterator();
- while(it.hasNext()){
- Object obj=it.next();
- if(newlist.contains(obj)){
- continue;
- }
- newlist.add(obj);
- }
- return newlist;
- }
-
- public static void sop(List list){
- Iterator it=list.iterator();
- while(it.hasNext()){
- System.out.println(it.next());
- }
- }
- }
复制代码 |