Java代碼
Map map = new HashMap();
Iterator it = map
while (it
Map
Object key = entry
Object value = entry
}
JDK
Java代碼
Map m = new HashMap();
for(Object o : map
map
}
返回的 set 中的每個元素都是一個 Map
private Hashtable<String
另外 我們可以先把hashMap 轉為集合Collection
//方法一: 用entrySet()
Java代碼
Iterator it = emails
while(it
Map
(
}
// 方法二
Java代碼
for (Map
(
}
// 方法三
Java代碼
Iterator it = emails
while (it
String key;
key=(String)it
(
}
// 方法四
Java代碼
for(Object m: emails
(
}
Map aa = new HashMap();
aa
//追加 替換用同樣的函數
aa
//刪除
for (Iterator i = aa
//遍歷
來個完整的
Java代碼
public static void main(String[] args) {
ArrayList<String> list = new ArrayList<String>();
HashMap<Object
TreeMap<Object
list
list
list
hash
hash
hash
hash
hash
hash
treeMap
treeMap
treeMap
treeMap
treeMap
treeMap
//list遍歷
for(String m: list){
System
}
// hashmap entrySet() 遍歷
for(Map
System
}
//hashmap keySet() 遍歷
for(Object m: hash
System
}
// treemap keySet()遍歷
for(Object m: treeMap
System
}
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26083.html