java map的遍歷
阿新 • • 發佈:2019-05-26
//從大的角度可以分為兩類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());
}