0
点赞
收藏
分享

微信扫一扫

javaSE关于集合的笔记(4)

干自闭 2022-02-11 阅读 103
package collection;
/*
* 深入Collection集合的contains方法
* */

import java.util.ArrayList;
import java.util.Collection;

public class CollectionTest04 {
    public static void main(String[] args) {
        // 创建集合对象
        Collection c = new ArrayList();

        // 向集合中存储元数据
        String s1 = new String("abc");
        c.add(s1);
        String s2 = new String("def");
        c.add(s2);

        // 集合中元素的个数
        System.out.println("元素的个数是:" + c.size());

        String x = new String("abc");
        // c集合中是否包含x
        System.out.println(c.contains(x));
    }
}
举报

相关推荐

0 条评论