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());
}