Java基础系列(十五)集合、迭代

一、集合

1.1 集合的继承实现关系

使用ArrayList类时,该类已经把所有抽象方法进行了重写。那么,实现Collection接口的所有子类都会进行方法重写。
Collecton接口常用的子接口有:List接口、Set接口
List接口常用的子类有:ArrayList类、LinkedList类
Set接口常用的子类有:HashSet类、LinkedHashSet类

这里写图片描述
Map接口:
这里写图片描述

1.2 集合Collection的方法

这里写图片描述
这里写图片描述

二、iterator接口

这里写图片描述

public static void main(String[] args) {
        Collection<String> coll = new ArrayList<String>();
        coll.add("2");
        coll.add("4");
        coll.add("6");
        coll.add("8");
        Iterator<String> it = coll.iterator();
        while( it.hasNext() ) {
            System.out.println(it.next());
        }
    }

猜你喜欢

转载自blog.csdn.net/weixin_41835916/article/details/79744753