Created
April 29, 2019 06:43
-
-
Save zhaoawd/655f1902b9fe6a278953b68107ee45ce to your computer and use it in GitHub Desktop.
[JAVA 对 map 的操作] 部分常用操作 #java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
java.util.Iterator 对 collection 进行迭代的迭代器。 | |
java.util.Iterator it = map.entrySet().iterator(); | |
while(it.hasNext()){ | |
java.util.Map.Entry entry = (java.util.Map.Entry)it.next(); | |
entry.getKey() //返回对应的键 | |
entry.getValue() //返回对应的值 | |
} | |
Map<String,String> testData = new HashMap<String, String>(); | |
(1) | |
Set<String> keys = testData.keySet(); | |
for(String key :keys){ | |
System.out.println(key+" "+testData.get(key)); | |
} | |
(2) | |
Set<Entry<String, String>> entries = testData.entrySet(); | |
for (Entry<String, String> entry : entries) { | |
System.out.println(entry.getKey()+":"+entry.getValue()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment