- package com.heima.Test16;
- import java.util.ArrayList;
- import java.util.Collection;
- import java.util.Iterator;
- @SuppressWarnings({ "rawtypes", "unchecked" })
- public class Test_demo {
- public static void main(String[] args) {
- ArrayList list = new ArrayList();
- list.add("a");
- list.add("a");
- list.add("a");
- list.add("b");
- list.add("b");
- ArrayList newList = demo1(list);
- System.out.println(newList);
- }
- public static ArrayList demo1(ArrayList list) {
- ArrayList newList = new ArrayList();
- Iterator it = list.iterator();
- while (it.hasNext()) {
- String temp = (String)it.next();
- if (!newList.contains(list)) {
- newList.add(temp);
- }
- }
- return newList;
- }
- }
复制代码
|
|