当前位置:网站首页>六种集合的遍历方式总结(List Set Map Queue Deque Stack)
六种集合的遍历方式总结(List Set Map Queue Deque Stack)
2022-07-06 09:19:00 【[email protected]】
List
方式一:for循环
for(int i = 0;i = list.size();i++){
System.out.println(list.get(i));
}
方式二:for each循环遍历
for(String s : list){
System.out.println(s);
}
方式三:iterator迭代器遍历
Iterator<String> it = list.iterator();
while(it.hasNext()){
System.out.println(it.next());
}
Set
方式一:for each
for(String s : set){
System.out.println(s);
}
方式二:iterator迭代器遍历
Iterator it = set.iterator();
while(it.hasNext()){
System.out.println(it.next());
}
Map
方式一:for each 遍历Map的key值
for(String key : map.keySet()){
Integer value = map.get(key);
System.out.println(key + "=' =value);
}
方式二:for each 同时遍历key和value
for(Map.Entry<String,Integer> entry : map.entrySet()){
String key = entry.getKey();
Integer value = entry.getValue();
System.out.println(key + "=" + value):
}
Queue队列(FIFO)
方式一: for each 遍历队列
for(String s : queue){
System.out.println(s);
}
方式二:iterator 迭代器遍历队列
String item = null;
while((item = queue.poll()) != null){
System.out.println(item);
}
Deque双端队列
iterator迭代器遍历
String item = null;
while((item = deque.poll.set()) != null){
System.out.println(item);
}
Stack栈(LIFO)
while(!stack.isEmpty()){
System.out.println(stack.poll());
}
版权声明
本文为[[email protected]]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_49194330/article/details/124734835
边栏推荐
- TYUT太原理工大学2022软工导论大题汇总
- 13 power map
- 十分钟彻底掌握缓存击穿、缓存穿透、缓存雪崩
- 阿里云微服务(一)服务注册中心Nacos以及REST Template和Feign Client
- [GNSS] robust estimation (robust estimation) principle and program implementation
- TYUT太原理工大学2022数据库大题之数据库操作
- System design learning (III) design Amazon's sales rank by category feature
- Alibaba cloud side: underlying details in concurrent scenarios - pseudo sharing
- 阿里云微服务(四) Service Mesh综述以及实例Istio
- 167. Sum of two numbers II - input ordered array - Double pointers
猜你喜欢
Counter attack of flour dregs: redis series 52 questions, 30000 words + 80 pictures in detail.
[algorithm] sword finger offer2 golang interview question 9: subarray with product less than k
Record: the solution of MySQL denial of access when CMD starts for the first time
MySQL 30000 word essence summary + 100 interview questions, hanging the interviewer is more than enough (Collection Series
Introduction and use of redis
架构师怎样绘制系统架构蓝图?
Redis介绍与使用
Quickly generate illustrations
Inheritance and polymorphism (Part 2)
Alibaba cloud microservices (IV) service mesh overview and instance istio
随机推荐
TYUT太原理工大学2022“mao gai”必背
Design a key value cache to save the results of the most recent Web server queries
Dark chain lock (lca+ difference on tree)
IText 7 generate PDF summary
Fgui project packaging and Publishing & importing unity & the way to display the UI
Tyut Taiyuan University of technology 2022 introduction to software engineering
错误: 找不到符号
How do architects draw system architecture blueprints?
[algorithm] sword finger offer2 golang interview question 3: the number of 1 in the binary form of the first n numbers
Shortest Hamilton path (pressure DP)
Tyut Taiyuan University of technology 2022 introduction to software engineering summary
[algorithm] sword finger offer2 golang interview question 6: sum of two numbers in the sorting array
XV Function definition and call
Differences and application scenarios between MySQL index clock B-tree, b+tree and hash indexes
[algorithm] sword finger offer2 golang interview question 2: binary addition
One article to get UDP and TCP high-frequency interview questions!
GNSS positioning accuracy index calculation
TYUT太原理工大学2022数据库题库选择题总结
TYUT太原理工大学2022数据库大题之E-R图转关系模式
Inheritance and polymorphism (I)