Java中怎樣遍歷Map的所有的元素

2021-05-22 21:12:55 字數 491 閱讀 9293

jdk1.4中

map map = new hashmap();

iterator it = map.entryset().iterator();

while (it.hasnext()) 返回的 set 中的每個元素都是乙個 map.entry 型別。

private hashtable emails = new hashtable(); 另外 我們可以先把hashmap 轉為集合collection,再迭代輸出,不過得到的物件

//方法一: 用entryset()

iterator it = emails.entryset().iterator();

while(it.hasnext())

來個完整的,包含treeset的元素內部排序的

public static void main(string args) {

arraylist list = new arraylist();

hashmap

Java中怎樣遍歷Map的所有的元素

jdk1.4中 map map new hashmap iterator it map.entryset iterator while it.hasnext jdk1.5中 應用新特性for each迴圈 map m new hashmap for object o map.keyset 返回的 s...

JAVA遍歷Map所有元素

jdk1.5 map map new hashmap for object obj map.keyset jdk1.4 map map new hashmap iterator iter map.entryset iterator while iter.hasnext 第一種 map map new...

java中Map的遍歷

map遍歷的常用方法 mapmap new hashmap map.put 0,zero map.put 1,one map.put 2,two 方法一 最常用的 獲取key值 collectionk map.keyset iteratoritk k.iterator system.out.prin...