/*
高级for循环
格式:for(数据类型 变量名:被遍历的集合(collection或数组))
队集合进行遍历只能获取元素,但是不能对集合操作
迭代器除了遍历,还可以进行remove集合中元素的动作
如果使用ListIterator,还可以在遍历过程中进行增删改查的动作
chuantong for循环和高级For有什么区别?
高级for有一个局限性,必须有被遍历的目标,
建议在遍历数组的时候,还是i希望使用传统for,因为传统for可以定义角标;
*/
class ForEachDemo{
punlic static void main(String[] args){
a1.add("sdfjs");
a1.add("fgs");
a1.add("sdfjs");
for(String s:a1){
s="kk";
System.out.println(s);
}
Iterator<String> it==a1.iterator();
while(it.hasNext()){
System.out.pritnln(it.next());
}
int [] arr={3,5,1};
for(int i:arr){
System.out.println(i);
}
HashMap<Integer,String> hm=new HashMap<>();
hm.put(1,"a");
hm.put(2,"ba");
hm.put(3,"ban");
hm.put(4,"ab");
Set<Integer> keySet=hm.keySet();
for(Integer i:keySet){
System.out.println(i+hm.get(i));
}
//Set<Map.Entry<Integer,String>> entrySet=hm.entrySet();
for(Map.Entry<Integer,String> mo:hm.EntrySet()){
System.out.println(mo.getKey()+me.getValue());
}
}
}