Java集合类的组织结构和继承、实现关系详解
作者:lashou 时间:2023-03-09 10:48:50
Collection继承、实现关系如下(说明(I)表示接口, (C)表示Java类,<--表示继承,<<——表示实现):
(I)Iterable
|<-- (I)Collection
|<-- (I)List
|<<—— (C)ArrayList
|<<—— (C)LinkedList
|<<—— (C)Vector
|<-- (I)Set
|<<—— (C)HashSet
|<-- (I)Queue [kju]
Map继承、实现关系如下
Map
|<<—— (C)HashMap
|<<—— (C)HashTable
Iterable:
package java.lang;
import java.util.Iterator;
public interface Iterable<T> {
Iterator<T> iterator();
}
Iterator:
package java.util;
public interface Iterator<E> {
boolean hasNext();
E next();
void remove();
}
Collection:
package java.util;
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);
boolean add(E e);
boolean remove(Object o);
boolean containsAll(Collection<?> c);
boolean addAll(Collection<? extends E> c);
boolean removeAll(Collection<?> c);
boolean retainAll(Collection<?> c);
void clear();
boolean equals(Object o);
int hashCode();
}
Map:
package java.util;
public interface Map<K,V> {
int size();
boolean isEmpty();
boolean containsKey(Object key);
boolean containsValue(Object value);
V get(Object key);
V put(K key, V value);
V remove(Object key);
void putAll(Map<? extends K, ? extends V> m);
void clear();
Set<K> keySet();
Collection<V> values();
Set<Map.Entry<K, V>> entrySet();
interface Entry<K,V> {
K getKey();
V getValue();
V setValue(V value);
boolean equals(Object o);
int hashCode();
}
boolean equals(Object o);
int hashCode();
}
1、Collection和Map的区别
Collection和Map最大的区别就是Collection存储的是一组对象;Map是以“键值对”的形式对对象进行的管理。
2、Iterable和Iterator
Iterator是迭代器,Iterable是接口。很多类,像List、Set、HashMap不直接实现迭代器接口Iterator,而是去实现Iterable接口,是因为:
Iterator的方法next()和hasNext()是依赖当前迭代位置的,直接实现Iterator,集合在不同方法间传递时,会包含一个当前迭代位置的指针;
而Iterable每次调用都会返回一个从头开始计数的迭代器。
3、Collection和Collections的区别
Collection是一个集合接口。它提供了对集合对象进行进本操作的通用接口方法。
Collections是一个工具类。内有多个对集合对象进行操作的静态方法,不能实例化。
来源:http://www.cnblogs.com/lashou/p/6077560.html
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
C#微信开发之获取接口调用凭据
![](https://img.aspxhome.com/file/2023/0/108780_0s.png)
C# 使用Proxy代理请求资源的方法步骤
![](https://img.aspxhome.com/file/2023/4/129614_0s.jpg)
一篇文章带你从java字节码层理解i++和++i
![](https://img.aspxhome.com/file/2023/9/63849_0s.png)
Java实现文件批量重命名具体实例
![](https://img.aspxhome.com/file/2023/2/125652_0s.png)
java面试常问的Runnable和Callable的区别
java 保留两位小数的几种方法
java实现归并排序算法
![](https://img.aspxhome.com/file/2023/3/77063_0s.jpg)
浅谈c++11线程的互斥量
![](https://img.aspxhome.com/file/2023/6/116586_0s.png)
Java中双大括号初始化的理解与使用
Android短信验证码自动填充功能
![](https://img.aspxhome.com/file/2023/0/138020_0s.png)
flutter TextField换行自适应的实现
.net从服务器下载文件中文名乱码解决方案
springmvc分层领域模型概念详解
![](https://img.aspxhome.com/file/2023/0/66660_0s.jpg)
C#实现向函数传递不定参数的方法
C#中数组初始化与数组元素复制的方法
轻松掌握Java迭代器模式
Springcloud seata nacos环境搭建过程图解
![](https://img.aspxhome.com/file/2023/1/61341_0s.png)
Java中BufferedReader与BufferedWriter类的使用示例
Android自定义轮播图效果
Android实现左右滑动切换图片
![](https://img.aspxhome.com/file/2023/8/109178_0s.gif)