循环map

public static void main(String[] args) {
  Map<String, String> map = new HashMap<String, String>();
  map.put("1", "a");
  map.put("222", "aa");
  map.put("33", "aaa");
  Set<String> set = new HashSet<String>();
  set= map.keySet();
  for (String key : set) {
   //循环取出了你map里面的值然后再调用你的sql方法想怎么存就怎么存
   System.out.print(key+" = "+map.get(key));
  }
 }

=============================================================

Map a = new HashMap();
//方法一
Iterator it = a.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pairs = (Map.Entry) it.next();
System.out.println(pairs.getValue());
}
//以下方法需要jdk5以上支持
//方法二
for(String str:akeySet()){ 
System.out.println(str); 
}
//方法三
for(Map.Entry entry:a.entrySet()){
System.out.println(entry.getKey()+"="+entry.getValue()); 
}


你可能感兴趣的:(循环,map)