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集合中成功添加");
        }
    }

}
View Code

相关文章:

  • 2021-09-26
  • 2021-04-11
  • 2022-01-03
  • 2021-11-18
  • 2022-03-08
  • 2022-12-23
  • 2022-12-23
  • 2021-07-06
猜你喜欢
  • 2022-01-14
  • 2021-12-18
  • 2022-02-25
  • 2022-12-23
  • 2021-12-05
  • 2021-05-22
  • 2021-12-26
相关资源
相似解决方案