深入Java集合Collection

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wydyd110/article/details/86476846

1. Java集合框架图

更详细版

Java集合主要有3种重要的类型

List:是一个有序集合,可以放重复的数据

  • ArrayList:基于可变数组
  • LinkedList:基于链表数据结构

Set:是一个无序集合,不允许放重复的数据

  • HashSet:无序的不可重复的
  • TreeSet:可以对Set集合进行排序,默认自然排序(即升序)
  • LinkedHashSet:基于哈希表和链接列表

Map:是一个无序集合,集合中包含一个键对象,一个值对象键对象不允许重复,值对象可以重复(身份证号姓名

  • HashMap:
  • HashTable:
  • TreeMap:
  • LinkedHashMap:

2 List

2.1 ArrayList

2.1.1 set

    /**
     * Replaces the element at the specified position in this list with
     * the specified element.
     * 用指定的元素替代此列表中指定位置上的元素
     */
    public E set(int index, E element) {
        Objects.checkIndex(index, size);//检查index是否合法
        E oldValue = elementData(index);
        elementData[index] = element;//赋值
        return oldValue;
    }

2.1.2 add

//将指定的元素添加到列表的尾部
public boolean add(E e){
    ensureCapacity(size+1);确保容量满足
    elementData[size++] = e;
    return true;
}

元素往后移动会出现要扩容的情况

2.1.3 remove

2.2 LinkedList


本文学习自

学堂在线-清华大学-许斌《JAVA程序设计进阶》

猜你喜欢

转载自blog.csdn.net/wydyd110/article/details/86476846