The relationship between the framework and a set of Java classes interfaces

 

table of Contents

The relationship between the framework and a set of Java classes interfaces

Collection common method 

Map common method 

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. Collection : for storing a set of managed objects Objects , these objects become elements are generally elements
2. the Set : elements can not be repeated, hidden behind the Find / Search semantics
3. SortedSet : an ordered set of elements can not be repeated
4. List : linear structure
5. The Queue : Queue
6. The the Deque : deque
7. the Map : key-value pairs Key - Value - Pair , hidden behind the Find / Search semantics
8. The a SortedMap : an ordered set of key-value pairs
 
Second (right):

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 

 boolean add(E e);
将元素e放入集合中
 void clear();
删除集合中所有元素
boolean isEmpty();
判断集合是否为空
 boolean remove(Object e);
如果元素e出现在集合中,删除其中一个
int size(); 
返回集合中元素个数
Object[] toArray();
返回一个装有所有集合中元素的数组

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-键值对存储

 

 

发布了51 篇原创文章 · 获赞 14 · 访问量 2314

Guess you like

Origin blog.csdn.net/qq_41185460/article/details/103447518