集合源码分析[2]-AbstractList 源码分析

AbstractList

  1. 类型:抽象类

  2. 接口的继承以及实现关系

    1. 继承AbstractCollection
    2. 实现List接口

  1. 典型方法实现解析

    1. public List<E> subList(int fromIndex, int toIndex) 将集合从fromIndex到toIndex地方进行剪切
        public List<E> subList(int fromIndex, int toIndex) {
            return (this instanceof RandomAccess ?
                    new RandomAccessSubList<>(this, fromIndex, toIndex) :
                    new SubList<>(this, fromIndex, toIndex));
        }
    
    • 判断是否有随机访问的接口如果有则床架一个随机访问的List子集合,否则返回SubList
posted @ 2019-04-11 20:25  lonecloud  阅读(448)  评论(0编辑  收藏  举报
我的博客即将同步至 OSCHINA 社区,这是我的 OSCHINA ID:lonecloud,邀请大家一同入驻:https://www.oschina.net/sharing-plan/apply