1. 程式人生 > >java map的遍歷

java map的遍歷

//從大的角度可以分為兩類Set<String> set=map.keySet();這裡面還可以分為3類, 從set的角度來分

//Set<Map.Entry<String, String>> entery=map.entrySet();

public class Test {

public static void main(String[] args) {

 Map<String,String> map=new HashMap<String,String>();
 
 System.out.println(map.put("s", "mao"));
 
 System.out.println(map.put("sm", "mao"));
 
 Set<String> set=map.keySet();
 
 for(String s:set)
 
	 System.out.println(s+":"+map.get(s));
 
 Set<Map.Entry<String, String>> entery=map.entrySet();
 
 for(Entry<String, String> s:entery) {
 
	 System.out.println(s.getKey());
	 
	 System.out.println(s.getValue());
	 
	
  }