当前位置:网站首页>六种集合的遍历方式总结(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
边栏推荐
- Experience summary of autumn recruitment of state-owned enterprises
- 【快趁你舍友打游戏,来看道题吧】
- Tyut Taiyuan University of technology 2022 introduction to software engineering summary
- KF UD decomposition pseudo code implementation advanced [2]
- [GNSS data processing] Helmert variance component estimation analysis and code implementation
- GNSS positioning accuracy index calculation
- 继承和多态(下)
- TYUT太原理工大学2022软工导论大题汇总
- String class
- Introduction and use of redis
猜你喜欢
IPv6 experiment
Basic DOS commands
[dry goods] cycle slip detection of suggestions to improve the fixed rate of RTK ambiguity
[algorithm] sword finger offer2 golang interview question 12: the sum of the left and right sub arrays is equal
Conceptual model design of the 2022 database of tyut Taiyuan University of Technology
架构师怎样绘制系统架构蓝图?
Alibaba cloud microservices (III) sentinel open source flow control fuse degradation component
十分钟彻底掌握缓存击穿、缓存穿透、缓存雪崩
TYUT太原理工大学2022数据库大题之概念模型设计
C code implementation of robust estimation in rtklib's pntpos function (standard single point positioning spp)
随机推荐
阿里云微服务(三)Sentinel开源流控熔断降级组件
阿里云微服务(四) Service Mesh综述以及实例Istio
架构师怎样绘制系统架构蓝图?
Music playback (toggle & playerprefs)
Application architecture of large live broadcast platform
ROS machine voice
[rtklib] preliminary practice of using robust adaptive Kalman filter under RTK
系统设计学习(一)Design Pastebin.com (or Bit.ly)
【话题终结者】
121 distributed interview questions and answers
GNSS positioning accuracy index calculation
RTKLIB: demo5 b34f. 1 vs b33
Introduction and use of redis
记录:newInstance()过时的代替方法
Alibaba cloud microservices (II) distributed service configuration center and Nacos usage scenarios and implementation introduction
错误:排序与角标越界
Alibaba cloud microservices (I) service registry Nacos, rest template and feign client
Wechat applet development experience
[algorithm] sword finger offer2 golang interview question 1: integer division
Tyut Taiyuan University of technology 2022 "Mao Gai" must be recited