增强for循环:数组,Collection,Map
public class Demo {
public static void main(String[] args) {
int[] arr = {3,45,6,8,9};
for (int i : arr) {
System.out.println("数组:"+i);
}
ArrayList<String> list = new ArrayList<>();
list.add("java");
list.add("php");
for (String string : list) {
System.out.println("list:"+string);
}
TreeMap<String, String> map = new TreeMap<>();
map.put("01", "php");
map.put("02", "php2");
map.put("05", "php5");
Set<String> set1 = map.keySet();
for (String string : set1) {
System.out.println(map.get(string));
}
Set<Map.Entry<String, String>> set1 = map.entrySet();
for (Map.Entry<String, String> entry : set1) {
System.out.println(entry.getKey()+" "+entry.getValue());
}
}
}