1、Pg235--2分别向Set集合以及List集合中添加“A”,“a” , "c" , "C" , "a" 5个元素,观察重复值“a”能否在List集合以及Set集合中成功添加
package org.hanqi.array; import java.util.*; public class ZuoYe { public static void main(String[] args) { //Set 集合 Set<String> s=new HashSet<String>(); s.add("A"); s.add("a"); s.add("c"); s.add("C"); s.add("a"); if(s.size()==5) { System.out.println("重复值“a”能在Set集合中成功添加"); } else { System.out.println("重复值“a”不能在Set集合中成功添加"); } //List 集合 List<String> l=new ArrayList<String>(); l.add("A"); l.add("a"); l.add("c"); l.add("C"); l.add("a"); if(l.size()==5) { System.out.println("重复值“a”能在List集合中成功添加"); } else { System.out.println("重复值“a”不能在List集合中成功添加"); } } }