One.
There is another way to do this in the previous section, which is a bit of a hassle.
From the action just now, summed up a principle. The Map collection has no iterators, but we can convert the map to a collection of iterators, such as set.
What is this for? Why not return arrylist, which is to take all the keys, the key is unique, so the return should be set set, to ensure that the uniqueness of the element.
Next, in the API, there is also a way to return the set set, ( what is the special meaning of the set here ?). )
Now use it to complete the way to take out all the elements. Keyset are easy to understand, the inside is loaded with keys. However, EntrySet is the set view that returns the mappings that this map contains, what does a mapping relationship mean? The mapping relationship, which represents the correspondence between the key and the value, is stored in the corresponding relationship. Map.entry is a key-value relationship type, and for a moment explains why it is written. The corresponding relationship contains the key and the value.
The iterator should be followed by generics (not quite understood). It.next Returns the marriage certificate, the generics in set I don't care, but the generics in the iterator and the set are consistent.
A little tangled now, with a marriage certificate, how to take the key and value inside? Marriage certificate inside itself contains the key and value, composed of keys and values. Take the key and value of marriage certificate, marriage certificate is the most clear.
Click Map.entry<k,v> This marriage certificate, the method summary shows can be taken out, but also can be set. You can change the value of a key.
The results show no problem, this is the second method of removal. Draw a diagram to explain
What about the marriage certificate EntrySet got? It encapsulates the key and the value into an object, which is an element that saves four elements. One element in this is the Map,entry<key.value> object.
A lot of people to map.entry<key,value> a bit confused, for the wording a little confused.
This operation has been seen before,
Myentry is an interface that loads as the external interface loads.
Say the map interface first, and then look down to the nested class. Nested classes are built-in classes that are static interface,
Click inside to see, is the interface map is being closed. Have you ever seen a static comment? Only members, so it's a member.
Why do you have to define it inside and put it on the outside? Myentry is a content that contains keys and values, is a mapping of key and value objects, and there is only one existing map map that has a relationship. Instead, it encapsulates the relationship as an object, and the relationship accesses the keys and values in the map. That is, there are internal rules in the external rules, and internal rules directly access the contents of the external rules. What dot, all are nested.
The inner class itself is a form of encapsulation, but if it can be used externally, it is exposed.
The static interface in the interface
Java-preliminary Understanding-Common object API (set frame-focus Method EntrySet demo plot)