public static void test(){
int arr[] = {4,2,3};
for(int i : arr){
System.out.println(i);
}
}
下面是list
public static void test2(){
List list = new ArrayList();
list.add(1);
list.add(3);
list.add(4);
for(Object obj : list){
int i = (Integer)obj;
System.out.println(i);
}
}
下面是map
public void test3(){
Map map = new HashMap();
map.put(1, "aa");
map.put(2, "bb");
map.put(3, "dd");
for(Object obj : map.keySet()){
Integer k = (Integer) obj;
String v = (String)map.get(k);
System.out.println(k+"::"+v);
}
}
此方法比较适合取数据,不适合修改数据