Java 深入学习(1) —— 容器类(集合类)Set、List、Queue、Map 之间的区别

容器类大致分类示意图


(非精确分类)(绿色表示 interface,蓝色表示 class)

这里写图片描述

这里写图片描述


容器类类库划分


1、 Collection。一个独立元素的序列。这些元素都服从一条或多条规则。

List 必须按照插入顺序保存元素
Set 不能有重复元素
Queue 按照排队规则来确定对象产生的顺序

所有 Collection 都可以使用 foreach 遍历
Collection 在每个“槽”中只能保存一个元素

Collection 常用方法:

boolean add(E e)
Ensures that this collection contains the specified element (optional operation).

boolean addAll(Collection<? extends E> c)
Adds all of the elements in the specified collection to this collection (optional operation).

void    clear()
Removes all of the elements from this collection (optional operation).

boolean contains(Object o)
Returns true if this collection contains the specified element.

boolean containsAll(Collection<?> c)
Returns true if this collection contains all of the elements in the specified collection.

boolean equals(Object o)
Compares the specified object with this collection for equality.

int hashCode()
Returns the hash code value for this collection.

boolean isEmpty()
Returns true if this collection contains no elements.

Iterator<E> iterator()
Returns an iterator over the elements in this collection.

boolean remove(Object o)
Removes a single instance of the specified element from this collection, if it is present (optional operation).

int size()
Returns the number of elements in this collection.

2、Map。一组成对的“键值对”对象,允许使用 key 来查找 value。

Hash
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值