Map interface
The map interface is similar to the collection interface and is also one of the largest interfaces.
The difference between the 1,map interface and the collection interface;
The relationship between 2,map and Map.entry interface;
Common subclasses of 3,MAP interfaces: HashMap, HashTable, TreeMap, Weakhashmap;
The difference between 4,hashmap and Hashtable.
In a collection operation, each saved object is an object, but a pair of objects is saved in the map, and the form of the object is preserved in key–>value form.
Before the collection, list, Set, are single value operations, that is, only one object at a time, and map differs from them, each operation is a pair of objects,
Two-yuan even objects, each of the elements in a map is stored in a collection in key->value form.
Definition of Map:
public interface map<k,v>
Common methods in Map:
void clear ()/Empty the map collection
set<k> keyset ()//Get all key
collection<v> values ()//Remove all value
Set <Map.Entry<K,V>> EntrySet ()//Change Map object to set collection
Boolean equals (Object o)/object compare
int hashcode ()// Returns a hash code
int size ()//The length of the collection
Boolean isempty ()//To determine whether the collection is an empty
boolean containskey (Object key)//To determine whether the specified key exists
Boolean Containsvalue (object value)//To determine whether the specified value has a
v get (object key)//value
v put (K key,v value)// add element
V Remove (Object key) to the collection and delete the value
void Putall (map< extends K,? extends v> m) by key Add the contents of a map collection to another map
Map.entry Interface:
Map.entry is an internally defined interface in the map that is designed to hold key–>value content.
Map.entry Interface Definition:
public static Interface Map.entry<k,v>
Common methods in the Map.entry interface:
Boolean equals (Object o)/objects Compare
int hashcode ()//Return hash code K Getkey ()//Get
key
v getValue ()//Get value
V SetValue (V value)//Set value value
The relationship between the map and the Map.entry interface:
The map is in fact a Map.entry object, and each Map.entry object is a key value pair consisting of a key and a value.
Common subclasses of the map interface:
· HashMap: Orderly storage, is the new operation class, key does not allow duplication.
· HashTable: Orderly storage, is the old operation class, key does not allow duplication.
· TREEMAP: A map set that can be sorted, sorted by key in the collection, key does not allow duplication.
· Weakhashmap: A weakly referenced map collection that eliminates unwanted data when certain content in the collection is no longer in use, and can be recycled using GC.
· Identifyhashmap:key A collection of maps that can be duplicated.
You can use the Contailsxxx () method to find the specified key or whether the specified content exists.
If you want to output all keys, you can use the following methods:
Set<k> keyset () This method returns a set, you can use the iterator iteration to output the set.
Output all value, using the method:
Collection<v> VALUES ()