集合进阶——Collection

集合的体系结构(单列和双列)



Collection

List和Set区别

方法

add

clear

remove

size

boolean contains(是否包含)

boolean isEmpty


tips:判定对象是否存在时候,需要重写equals方法


Collection的遍历方式

for遍历只适用于list系列,无序的set遍历不了

三种方式

1.迭代器

2.增强for循环

3.lambda表达式


——>   迭代器遍历

Collection <String> coll = new ArrayList<>();

hasNext

   public static void main(String[] args) {
        Collection<String> coll = new ArrayList<>();

        coll.add("aaa");
        coll.add("bbb");
        coll.add("ccc");


        Iterator<String> iterator = coll.iterator();
        while (iterator.hasNext()) {
            String s = iterator.next();
            System.out.println(s);
        }
    }

——>增强for遍历(  快捷键 coll.for )

for (String s : coll) {
System.out.println(s);
}


——> lambda 表达式

forEach



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值