当前位置:网站首页>六种集合的遍历方式总结(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数据库大题之分解关系模式
- Decomposition relation model of the 2022 database of tyut Taiyuan University of Technology
- Exception: ioexception:stream closed
- MySQL Database Constraints
- Differences and application scenarios between MySQL index clock B-tree, b+tree and hash indexes
- Tyut Taiyuan University of technology 2022 introduction to software engineering
- 抽象类和接口
- [algorithm] sword finger offer2 golang interview question 7: 3 numbers with 0 in the array
- Experience summary of autumn recruitment of state-owned enterprises
- 编辑距离(多源BFS)
猜你喜欢

Alibaba cloud side: underlying details in concurrent scenarios - pseudo sharing
![[untitled]](/img/b1/9a2bebebb24132a405fc4e7d854e51.png)
[untitled]

Redis介绍与使用

抽象类和接口

记录:初次cmd启动MySQL拒接访问之解决

Novatel board oem617d configuration step record

The port is occupied because the service is not shut down normally

Differences and application scenarios between MySQL index clock B-tree, b+tree and hash indexes

2-year experience summary, tell you how to do a good job in project management
![[algorithm] sword finger offer2 golang interview question 1: integer division](/img/e6/f17135207b3540ec58e5a9eed54220.png)
[algorithm] sword finger offer2 golang interview question 1: integer division
随机推荐
2年经验总结,告诉你如何做好项目管理
TYUT太原理工大学2022数据库题库选择题总结
[rtklib] preliminary practice of using robust adaptive Kalman filter under RTK
WSL common commands
如何保障 MySQL 和 Redis 的数据一致性?
E-R graph to relational model of the 2022 database of tyut Taiyuan University of Technology
On March 15, the official version of go 1.18 was released to learn about the latest features and usage
Data manipulation language (DML)
Record: newinstance() obsolete replacement method
Abstract classes and interfaces
Tyut Taiyuan University of technology 2022 introduction to software engineering
TYUT太原理工大学2022“mao gai”必背
[algorithm] sword finger offer2 golang interview question 3: the number of 1 in the binary form of the first n numbers
Fgui project packaging and Publishing & importing unity & the way to display the UI
Answer to "software testing" exercise: Chapter 1
系统设计学习(二)Design a key-value cache to save the results of the most recent web server queries
Error: sorting and subscript out of bounds
Iterable、Collection、List 的常见方法签名以及含义
[algorithm] sword finger offer2 golang interview question 9: subarray with product less than k
Music playback (toggle & playerprefs)