zhailiming

  题目:分别向Set集合一级List集合中添加"A","a","C","c","a",五个元素,观察重复值"a"能否在List集合一级Set集合中成功添加

package com.hanqi.jihe;
import java.util.*;
public class Listjihe {

    public static void main(String[] args) {
        ArrayList<String> ls = new ArrayList<String>();
        
        ls.add("A");
        ls.add("a");
        ls.add("C");
        ls.add("c");
        
        if (ls.add("a"))
        {
            System.out.println("添加成功");
        }
        else
        {
            System.out.println("添加失败");
        }
        for(String i :ls)
        {
            System.out.println(i);
        }
        

    }

}

package com.hanqi.jihe;
import java.util.*;
public class Setjihe {

    public static void main(String[] args) {
        Set<String> se = new HashSet<String>();

        se.add("A");
        se.add("a");
        se.add("C");
        se.add("c");
        
        if (se.add("a"))
        {
            System.out.println("添加成功");
        }
        else
        {
            System.out.println("添加失败");
        }
        
        for(String i :se)
        {
            System.out.println(i);
        }
        
    }

}

分类:

技术点:

相关文章:

  • 2021-05-31
  • 2021-08-14
  • 2021-09-25
  • 2021-12-01
  • 2021-09-20
  • 2021-12-06
  • 2021-07-10
猜你喜欢
  • 2021-10-15
  • 2021-12-03
  • 2021-06-21
  • 2021-06-29
  • 2021-08-04
  • 2021-10-25
相关资源
相似解决方案