分別向Set集合和List集合中添加"A","a","c","C","a"5個元素, 觀察重復的a值能否在List或者Set中成功添加。
[java]
- package com.han;
-
- import java.util.*;
-
- /**
- * 分別向Set集合和List集合中添加"A","a","c","C","a"5個元素,
- * 觀察重復的a值能否在List或者Set中成功添加。
- * @author han
- *
- */
- public class SetVsList {
-
- @SuppressWarnings("unchecked")
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- @SuppressWarnings("rawtypes")
- TreeSet treeset=new TreeSet();
- treeset.add("A");
- treeset.add("a");
- treeset.add("c");
- treeset.add("C");
- treeset.add("a");
- @SuppressWarnings("rawtypes")
- List list=new ArrayList();
- list.add("A");
- list.add("a");
- list.add("c");
- list.add("C");
- list.add("a");
- @SuppressWarnings("rawtypes")
- Iterator it=treeset.iterator();
- System.out.println("Set集合中所有的元素:");
- while (it.hasNext()){
- System.out.println(it.next());
- }
- @SuppressWarnings("rawtypes")
- Iterator it2=list.iterator();
- System.out.println("List集合中所有的元素:");
- while (it2.hasNext()){
- System.out.println(it2.next());
- }
-
- }
-
- }