java常用集合类详解

java集合常用类图:

这里写图片描述

map类图:

这里写图片描述

详解:


Collection -----
    |
    |- - - - - - -   Set (set是基于map实现的,可以看作只有key,value为null的map,数据结构散列)


                       |
                       |- - - - - - - HashSet()   (Hashmap,散列表,数组+单向链表,性能居中)


                       |
                       |- - - - - - -  TreeSet   ((二叉树)红黑树,利用treeMap)


        |
        |- - - - - - - List  基于链表和数组


                       |
                       |- - - - - - - ArrayList  (数组,改查快,增删不易

    private static final int DEFAULT_CAPACITY = 10;

int newCapacity = oldCapacity + (oldCapacity >> 1);

初始大小10,每次扩大当前容量的0.5倍
)


                       |
                       |- - - - - - -  LinkedList (双向链表,增删易,改查慢)



         - - - - - - - Map


                       |
                       |- - - - - - - HashMap  (数组+散列表,无须)( 增删改查性能不高不快
初始大小16,装载因子0.75,(当容量大于当前容量的0.75时,扩充容量)最大容量为2*30
static final int DEFAULT_INITIAL_CAPACITY = 1 << 4; // aka 16

    /**
     * The maximum capacity, used if a higher value is implicitly specified
     * by either of the constructors with arguments.
     * MUST be a power of two <= 1<<30.
     */
    static final int MAXIMUM_CAPACITY = 1 << 30;

    /**
     * The load factor used when none specified in constructor.
     */
    static final float DEFAULT_LOAD_FACTOR = 0.75f;
)


                       |
                       |- - - - - - - TreeMap(二叉树,红黑树,增删改查性能不高不快)




                       |
                       |- - - - - - -  LinkedhashMap(hashmap的子类,可保存插入的顺序是linkedList和hashmap的结合)


凡是需要排序的对象集合都需要被排序的对象实现比较器(compareable)或者传入比较器comparetor,以确保对象具有比较能力

需要注意的是:使用hashset和hashmap等hash集合时,需要复写equals和hashcode方法,才能保证对象的比较,确定对象是否在对象意义上是否为同一对象,而非在内存中.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值