循环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()); 
}

时间: 2025-01-05 02:29:38

循环map的相关文章

Java:for循环Map

根据JDK5的新特性,用For循环Map,例如循环Map的Key Map<String, String> requestMap  for(String dataKey : requestMap.keySet())   {        System.out.print(dataKey +":");     System.out.println(requestMap.get(dataKey) );    } 循环输出Key和Value. 注意的是,paraMap 是怎么样定义

day46homework常量字符串拼接结构赋值扩展运算符for-of循环map函数默认值

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>01定义常量.html</title> <!--常量--> <script> //常量:1.一旦定义 不能更改 const PI = 3.14;  // console.log(PI); // PI = 3.1415; error 

mybatis循环map

一.循环key <foreach collection="map.keys" item="key" separator="and"> ${key} = #{key} </foreach> 二.循环values <foreach collection="map.values" item="value" separator="and"> ${value} 

用jquery循环map

前些天记录了java中for循环取map,发现用jquery的each一样可以取map(我称之为js的map,不要较劲),且顺序和map中顺序一致.废话少说,看代码 1 2 3 4 5 6 7 8 9 10 11 var map = {     地名: ["北京","天津","上海"],     民族: ["汉族","藏族","维吾尔族"] }; $.each(map,function(

jsp循环map map的key值不固定

<c:if test="${not empty parammap}"> <c:forEach items="${parammap }" var="map"> <c:forEach items="${map.key}" var="key" varStatus="s"> <input type="hidden" name=&quo

Java循环map集合

1 Map<Integer,String> map = new LinkedHashMap<Integer,String>(); 2 map.put(1, "星期一"); 3 map.put(2, "星期二"); 4 map.put(3, "星期三"); 5 map.put(4, "星期四"); 6 map.put(5, "星期五"); 7 map.put(6, "星期六&

【转】mybatis循环map的一些技巧

原文地址:http://blog.csdn.net/linminqin/article/details/39154133 循环key: <foreach collection="condition.keys" item="k" separator="and"> ${k} = #{k} </foreach> 循环values <foreach collection="condition.values"

循环Map方法

public static void main(String[] args) { Map<String, String> map = new HashMap<String, String>(); map.put("1", "张三"); map.put("2", "李四"); map.put("3", "王五"); /*方法一 :迭代程序*/ System.out.

mybatis 防止sql注入的 循环map写法

<foreach collection="condition.keys" item="k" separator="and"> <if test="null != condition[k]"> ${k} = #{condition[${k}]} </if> </foreach>