当前位置:网站首页>六种集合的遍历方式总结(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
边栏推荐
- Fundamentals of UD decomposition of KF UD decomposition [1]
- Introduction and use of redis
- 继承和多态(上)
- Alibaba cloud microservices (IV) service mesh overview and instance istio
- Record: newinstance() obsolete replacement method
- 一文搞定 UDP 和 TCP 高频面试题!
- 初识C语言(上)
- 13 power map
- The earth revolves around the sun
- MySQL Database Constraints
猜你喜欢

How to ensure data consistency between MySQL and redis?

继承和多态(上)

编辑距离(多源BFS)

TYUT太原理工大学2022软工导论大题汇总

Abstract classes and interfaces

System design learning (I) design pastebin com (or Bit.ly)

Conceptual model design of the 2022 database of tyut Taiyuan University of Technology

Dark chain lock (lca+ difference on tree)

Interview Essentials: talk about the various implementations of distributed locks!

系统设计学习(一)Design Pastebin.com (or Bit.ly)
随机推荐
Small exercise of library management system
XV Function definition and call
2年经验总结,告诉你如何做好项目管理
4.30 dynamic memory allocation notes
Fundamentals of UD decomposition of KF UD decomposition [1]
图书管理系统小练习
165. Compare version number - string
阿里云微服务(一)服务注册中心Nacos以及REST Template和Feign Client
Problems and solutions of robust estimation in rtklib single point location spp
Data manipulation language (DML)
MySQL backup -- common errors in xtrabackup backup
Tyut Taiyuan University of technology 2022 "Mao Gai" must be recited
TYUT太原理工大学2022软工导论大题汇总
Chromatic judgement bipartite graph
Answer to "software testing" exercise: Chapter 1
KF UD decomposition pseudo code implementation advanced [2]
阿里云微服务(三)Sentinel开源流控熔断降级组件
Role movement in the first person perspective
【话题终结者】
记录:下一不小心写了个递归