Java Colloection集合大纲

Colloection集合大纲

集合的框架结构图

List、set和map对比

Collection接口的方法

 
//集合数量
int size();
//判断集合是否为空
boolean isEmpty();
//是否包含实例o
boolean contains(Object o);
//返回集合的迭代器
Iterator<E> iterator();
//返回集合的Object数组
Object[] toArray();
//返回集合的T数组
<T> T[] toArray(T[] a);
//添加元素
boolean add(E e);
//移除元素
boolean remove(Object o);
//Returns true if this collection contains all of the elements in the specified collection.
boolean containsAll(Collection<?> c);
//Adds all of the elements in the specified collection to this collection (optional operation).
boolean addAll(Collection<? extends E> c);
//Removes all of this collection's elements that are also contained in the specified collection (optional operation).
boolean removeAll(Collection<?> c);
//过滤元素
default boolean removeIf(Predicate<? super E> filter);
//保留集合c中的元素,即交集
boolean retainAll(Collection<?> c);
//清空元素
void clear();
//Compares the specified object with this collection for equality.
boolean equals(Object o);
//任何重写Object.equals方法的类都必须重写Object.hashCode方法,以满足Object.hashCode方法的一般契约。其中, c1.equals(c2) 表示c1.hashCode()= = c2.hashCode()。
int hashCode();
//1.8可拆分的迭代器
default Spliterator<E> spliterator() {
return Spliterators.spliterator(this, 0);
}
//Returns a sequential Stream with this collection as its source.
default Stream<E> stream() {
return StreamSupport.stream(spliterator(), false);
}

常用集合的分类

一、List

Collection 接口的接口 对象的集合(单列集合)
├——-List 接口:元素按进入先后有序保存,可重复
│—————-├ LinkedList 接口实现类, 链表, 插入删除, 没有同步, 线程不安全
│—————-├ ArrayList 接口实现类, 数组, 随机访问, 没有同步, 线程不安全
│—————-└ Vector 接口实现类 数组, 同步, 线程安全
│ ———————-└ Stack 是Vector类的实现类

二、set

Collection 接口的接口 对象的集合(单列集合)
└——-Set 接口: 仅接收一次,不可重复,并做内部排序
├—————-└HashSet 使用hash表(数组)存储元素
│————————└ LinkedHashSet 链表维护元素的插入次序
└ —————-TreeSet 底层实现为二叉树,元素排好序

三、Map

Map 接口 键值对的集合 (双列集合)
├———Hashtable 接口实现类, 同步, 线程安全
├———HashMap 接口实现类 ,没有同步, 线程不安全-
│—————–├ LinkedHashMap 双向链表和哈希表实现
│—————–└ WeakHashMap
├ ——–TreeMap 红黑树对所有的key进行排序
└———IdentifyHashMap

集合详解链接

List详解
Set详解
map详解

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值