增强for循环底层依然是迭代器。 因为单步调试,我们是可以进来的。
增强for也是我们在开发中使用最多的一种遍历方式。
可以实现各种数据类型的遍历。
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35package org.example.testFor; import com.google.common.collect.Maps; import com.google.common.collect.Sets; import java.util.Map; import java.util.Set; public class Main { public static void main(String[] args) { // 遍历Set Set<Integer> set = Sets.newHashSet(1, 2, 5, 4, 3); for (Integer num : set) { System.out.println(num); } // 遍历HashMap Map<Integer, String> map = Maps.newHashMap(); map.put(1, "123"); map.put(2, "456"); for (Integer key : map.keySet()) { System.out.println(key + ":" + map.get(key)); } } } /* 1 2 3 4 5 1:123 2:456 */
最后
以上就是痴情皮卡丘最近收集整理的关于增强for循环 1.底层依然是迭代器 2.可遍历各种类型的数据的全部内容,更多相关增强for循环内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复