table of Contents
The relationship between the framework and a set of Java classes interfaces
List, Map, Set application scenarios
The relationship between the framework and a set of Java classes interfaces
First of all, I found a description of this chart compares the image
The relationship between the collections framework in Java classes and interfaces:
The first graph (left):
Collection inherited the Iterable interface. List is the list, Queue is a queue, Set is a collection of note elements in the collection is not repeated. Abstract AbstractList queue, inherited List; Deque deque is inherited Queue; SortedSet ordered set is inherited Set.
Detailed look at the bottom of the class we will find
1. stack is the stack, inherited the Vector
2. ArrayList is the order of the table, the bottom is achieved with an array of
3. LinkedList is a linked list, the bottom is doubly-linked list implementation
4. PriorityQueue is the priority queue, are implemented with underlying stack (binary)
5. the TreeSet is a binary search tree (sorting)
6. the hash table HashSet
The relationship between the interface:
1. HashMap implements the Map, is the hash table (having no sorting function)
2. the TreeMap achieved SortMap, a binary search tree (having a sorting function)
PS:
the Map data is stored according to the value of key, hash. Is then stored in the target position of the object hash table index
Key value is generally not repeated (if repeated will be covered)
CURD hash table of the time complexity is O (1)
Collection common method
|
|
|
|
|
|
|
|
|
|
|
|
Map common method
V get(Object k);
|
The designated k find the corresponding v |
V getOrDefault(Object k, V defaultValue);
|
根据指定的 k 查找对应的 v,没有找到用默认值代替 |
V put(K key, V value)
|
将指定的 k-v 放入 Map |
boolean containsKey(Object key)
|
判断是否包含 key |
boolean containsValue(Object value)
|
判断是否包含 value |
Set<Map.Entry<K, V>> entrySet()
|
将所有键值对返回 |
boolean isEmpty()
|
判断是否为空 |
int size()
|
返回键值对的数量 |
基本打印方式
基本方式主要有三种:
1.直接打印
System.out.println(list);
2.for-each打印(一个类只有实现Iterable接口,才能用for-each打印)
for(Map.Entry<String,String> entry : map.entrySet()) {
System.out.println(entry.getKey());
System.out.println(entry.getValue());
}
3.Array
System.out.println(Arrays.asList());
List、Map、Set的应用场景
List-有序可重复
ArrayList:底层由数组实现,查询快,增删慢。线程不安全,效率高。
Vector:底层由数组实现,查询快,增删慢。线程安全,效率底。
LinkedList:底层由链表实现,查询慢,增删快。线程不安全,效率高。
Set-无序唯一
Map-键值对存储