List迴圈與Map迴圈的總結

2021-07-10 18:29:50 字數 757 閱讀 5292

做了一下list和map的總結,沒有什麼技術含量,就全當複習了一下api。

測試環境是在junit4下,如果沒有自己寫乙個main方法也是一樣的。

首先是list的三種迴圈:

@test

public void forlisttest()

// foreach相對比for來講,不需要知道集合的長度

for (string list : list)

// for迴圈既需要知道集合的大小,而且要求是有序的

for (int i = 0; i < list.size(); i++)

}

然後是map的四種迴圈:

@test

public void formaptest()

set> entryset = map.entryset();

的迭代方法

for (@suppresswarnings("rawtypes")

iterator iterator = entryset.iterator(); iterator.hasnext();)

//3.推薦,容量最大

for (entryentry : entryset)

collectionvalues = map.values();

//4.只迴圈出value的方法

for (string value : values)

}

js中的forEach迴圈與map迴圈

在js中進行陣列迴圈時經常會用到foreach方法和map方法,下面就來看一下這兩種遍歷方法的區別。vararray 1,2,3,4,5 var array1 array.foreach function val vararray2 array.map function val console.lo...

關於map迴圈

map 方法建立乙個新陣列,其結果是該陣列中的每個元素都呼叫乙個提供的函式後返回的結果,不能改變原始陣列。該函式接受的三個引數為 當前元素 當前索引 當前被呼叫的陣列 var numbers 1 4,9 var roots numbers.map math.sqrt roots的值為 1,2,3 n...

Map迴圈遍歷的方法

map迴圈遍歷的方法 map迴圈遍歷的方法 map迴圈遍歷的方法 下面是 部分 mapmap new hashmap map.put key1 value1 map.put key2 value2 map.put key3 value3 第一種 普遍使用,二次取值 system.out.printl...