【Java】集合之Collection接口
2021/7/5 1:22:24
本文主要是介绍【Java】集合之Collection接口,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
/** * The root interface in the collection hierarchy(单列集合),Map是双列集合 */ public interface Collection<E> extends Iterable<E> { /** * 查询集合元素总个数 */ int size(); /** * 判断集合是否为空 */ boolean isEmpty(); /** * 判断集合是否包含指定元素 */ boolean contains(Object o); /** * 返回迭代器,不保证迭代器中元素是有序的(添加和遍历顺序一致),除非是有序集合 */ Iterator<E> iterator(); /** * 转化为数组 */ Object[] toArray(); /** * 转化为数组 */ <T> T[] toArray(T[] a); /** * 转化为数组 */ default <T> T[] toArray(IntFunction<T[]> generator) { return toArray(generator.apply(0)); } /** * 添加元素 */ boolean add(E e); /** * 移除元素 */ boolean remove(Object o); /** * 判断是否包含指定集合中的所有元素 */ boolean containsAll(Collection<?> c); /** * 添加集合 */ boolean addAll(Collection<? extends E> c); /** * 移除指定集合中的所有元素 */ boolean removeAll(Collection<?> c); /** * 移除特定元素 */ default boolean removeIf(Predicate<? super E> filter) { Objects.requireNonNull(filter); boolean removed = false; final Iterator<E> each = iterator(); while (each.hasNext()) { if (filter.test(each.next())) { each.remove(); removed = true; } } return removed; } /** * 当前集合与指定集合取交集,交集保存到当前集合 */ boolean retainAll(Collection<?> c); /** * 清空集合 */ void clear(); /** * 判断是否相等 */ boolean equals(Object o); /** * 返回hash值 */ int hashCode(); /** * 略 */ @Override default Spliterator<E> spliterator() { return Spliterators.spliterator(this, 0); } /** * 略 */ default Stream<E> stream() { return StreamSupport.stream(spliterator(), false); } /** * 略 */ default Stream<E> parallelStream() { return StreamSupport.stream(spliterator(), true); } }
这篇关于【Java】集合之Collection接口的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-10-06小米11i印度快充版ROM合集:极致体验,超越期待
- 2024-10-06【ROM下载】小米11i 5G 印度版系统, 疾速跃迁,定义新速度
- 2024-10-06【ROM下载】小米 11 青春活力版,青春无极限,活力全开
- 2024-10-05小米13T Pro系统合集:性能与摄影的极致融合,值得你升级的系统ROM
- 2024-10-01基于Python+Vue开发的医院门诊预约挂号系统
- 2024-10-01基于Python+Vue开发的旅游景区管理系统
- 2024-10-01RestfulAPI入门指南:打造简单易懂的API接口
- 2024-10-01初学者指南:了解和使用Server Action
- 2024-10-01Server Component入门指南:搭建与配置详解
- 2024-10-01React 中使用 useRequest 实现数据请求