tags: Java foundation knowledge hashmap java
I believe that everyone must be unfamiliar with Hashmap, and it is also more proficient. He here, the blogger helps everyone review the source code.
First give you a picture

This is a HashMap very clear that HashMap is composed of key values.
problem
answer Put KEY and VALUE in an object and place the object in an array.
Let's take a look at the bottom source code

Object is entry (node implements map.entry)
So see the first picture.Each line can see as an Entry object as a whole as an arrayThen, the first traversal method came out.
for (Map.Entry entry:hashMap.entrySet()) {// hashmap is an instantiated object
System.out.println(entry.getKey());
System.out.println(entry.getValue());
}
For the first picture, we look at the first line (Key) is a set collection (the bottom of the SET is MAP implementation)
We can traverse all KEY values.
Set<String> keys= hashMap.keySet();
for (String key :keys) {
System.out.println(hashMap.get(key));
}
By the way, the second line of the first picture (Value) is a collection of Collection, we can pass
.VALUES Gets Value Collection

Writing one Writing two...
Which uses a fifth of Java8 lambda expression to traverse....
keySetentrySetHashMapMap.foreachlambda AI developers involved Baidu contest to win prizes 750,000 bonus +25 Wan, (providing tutorial) plus group: 418 589 053 >>> Abo...
Preface: Gravity collection HashMap is understandable, by its ownArray + list / black treeConfiguration (JDK 1.8), so that the advantages demonstrated HashMap: Fast array of query efficiency; List ins...
HashMap traversal HashMap is a container for storing data in the form of (key, value). There are 4 traversal methods; Ordinary traversal This is the ordinary traversal method of HashMap; by strengthen...
HashMap traversal HashMap sort...
I went for an interview today. The interviewer asked this question, and found that he had used HashMap and HashSet for so long, but he could barely think of a method. To sum up HashMap traversal metho...