1package com.zlh; 2 3import java.util.ArrayList; 4import java.util.HashMap; 5import java.util.Iterator; 6import java.util.Map; 7import java.util.Map.Entry; 8import java.util.Set; 9 10publicclass TravelseDemo { 11 12publicstaticvoid main(String[] args) { 13// 数组遍历 14 System.out.println("1 数组遍历"); 15 String[] str1 = { "数", "组", "遍", "历" }; 16 arrayTravelse(str1); 17 System.out.println("==================="); 18// 字符串遍历 19 System.out.println("2 字符串遍历"); 20 String str2 = "字符串遍历"; 21 stringTravelse(str2); 22 System.out.println("==================="); 23// list遍历 24 ArrayListlist =new ArrayList(); 25 list.add("集"); 26 list.add("合"); 27 list.add("遍"); 28 list.add("历"); 29// list遍历-for-each 30 System.out.println("3 list遍历-for-each"); 31 forTravelse(list); 32 System.out.println("==================="); 33// list遍历-迭代器 34 System.out.println("4 list遍历-迭代器"); 35 iteratorTravelse(list); 36 System.out.println("==================="); 37// map遍历 38 Mapmap =new HashMap(); 39 map.put("jack", 1); 40 map.put("tom", 2); 41 map.put("jerry", 3); 42// map遍历-for-each与keySet 43 System.out.println("5 map遍历-for-each与keySet"); 44 forKeySetTravelse(map); 45 System.out.println("==================="); 46// map遍历-迭代器与keySet 47 System.out.println("6 map遍历-迭代器与keySet"); 48 iteratorKeySetTravelse(map); 49 System.out.println("==================="); 50// map遍历-for-each与entry 51 System.out.println("7 map遍历-for-each与entry"); 52 forEntryTravelse(map); 53 System.out.println("==================="); 54// map遍历-迭代器与entry 55 System.out.println("8 map遍历-迭代器与entry"); 56 iteratorEntryTravelse(map); 57 } 58 59// 数组遍历 60privatestaticvoid arrayTravelse(String[] str) { 61for (int i = 0; i