Map of Java collection framework

Map:

Add a pair of elements at a time (key - > value)

Two column set, key value pair

Common methods:

1. Add

V put (k key, V value) will update the value corresponding to the key and return the replaced value

2. Delete

Clear (): clear the collection

V remove (k key): deletes the key value pair according to the specified key

3. Judgment:

Boolean containsKey(key)

Boolean containsValue(value);

Boolean isEmpty();

4. Get

Value get (key): get the value through the key. If there is no key, null will be returned.

Int size(): get the number of key value pairs

Common subclasses of map:

Hashtable (available in 1.0): the internal structure is a hash table, which is synchronous. Null is not allowed as a key or value

Hashtable subclass: properties is used to store the configuration information of key value pair type and cooperate with io

HashMap: the internal hash table is out of sync. Null is allowed as key or value

Treemap: it is a binary tree inside. It is out of sync and can sort the keys in the collection

demo:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>