Map<String, String> map = new HashMap<String, String>();
map.put("key1", "value1");
map.put("key2", "value2");
map.put("key3", "value3"); //第一种:普遍使用,二次取值
System.out.println("通过Map.keySet遍历key和value:");
for (String key : map.keySet()) {
System.out.println("key= "+ key + " and value= " + map.get(key));
} //第二种
System.out.println("通过Map.entrySet使用iterator遍历key和value:");
Iterator<Map.Entry<String, String>> it = map.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, String> entry = it.next();
System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue());
} <span style="color:#FF0000;"> //第三种:推荐,尤其是容量大时</span>
System.out.println("通过Map.entrySet遍历key和value");
for (Map.Entry<String, String> entry : map.entrySet()) {
System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue());
} //第四种
System.out.println("通过Map.values()遍历所有的value,但不能遍历key");
for (String v : map.values()) {
System.out.println("value= " + v);
}
public class HashMapAdapter extends BaseAdapter {

    private HashMap<String, String> mData = new HashMap<String, String>();
private String[] mKeys;
public HashMapAdapter(HashMap<String, String> data){
mData = data;
mKeys = mData.keySet().toArray(new String[data.size()]);
} @Override
public int getCount() {
return mData.size();
} @Override
public Object getItem(int position) {
return mData.get(mKeys[position]);
} @Override
public long getItemId(int arg0) {
return arg0;
} @Override
public View getView(int pos, View convertView, ViewGroup parent) {
String key = mKeys[pos];
String Value = getItem(pos).toString(); //do your view stuff here return convertView;
}
}

Map<String, String>的数据处理以及ListView的适配器的更多相关文章

  1. 入门:Java Map<String,String>遍历及修改

    重点:在使用Map时注意key-value,key用于检索value的内容. 在正常情况下,可以不允许重复:在java中分为2中情况,一是内存地址重复,另一个是不同的地址但内容相等. 在使用Map是一 ...

  2. alibaba fastjson List<Map<String, String>>2Str

    import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map; impo ...

  3. getParameterMap()的返回值为Map<String, String[]>,从其中取得请求参数转为Map<String, String>的方法如下:

    直接遍历报错:[Ljava.lang.String;@44739f3f Map<String, String> tempMap = new HashMap<String, Strin ...

  4. JAVA/Android Map与String的转换方法

    在Android开发中 Map与String的转换在,在一些需求中经常用到,使用net.sf.json.JSONObject.fromObject可以方便的将string转为Map.但需要导入jar包 ...

  5. FastJSON 简介及其Map/JSON/String 互转

    在日志解析,前后端数据传输交互中,经常会遇到 String 与 map.json.xml 等格式相互转换与解析的场景,其中 json 基本成为了跨语言.跨前后端的事实上的标准数据交互格式.应该来说各个 ...

  6. 使用STL map 用 string 做索引 插入删除数据

    1.代码 #include <map> #include <string> #include <stdio.h> #include <vector> # ...

  7. POJ2503——Babelfish(map映射+string字符串)

    Babelfish DescriptionYou have just moved from Waterloo to a big city. The people here speak an incom ...

  8. JAVA中List转换String,String转换List,Map转换String,String转换Map之间的转换类

    <pre name="code" class="java"></pre><pre name="code" cl ...

  9. Android List<Map<String,String>转json(例子)

    package com.armslee.json.test.cases; import java.util.ArrayList; import java.util.HashMap; import ja ...

随机推荐

  1. pip install 安装提示unknown 包

    pip install setuptools --upgrade should fix the issue

  2. Spring Cloud 模块简介

    Spring Cloud Netflix对微服务的支持还有: Hystrix: 断路器和资源隔离 Feign: 声明式HTTP REST请求客户端 Ribbon: 与Eureka结合实现软负载均衡 Z ...

  3. Redis(十二):redis两种持久化方法对比分析

    前言 最近在项目中使用到Redis做缓存,方便多个业务进程之间共享数据.由于Redis的数据都存放在内存中,如果没有配置持久化,redis重启后数据就全丢失了,于是需要开启redis的持久化功能,将数 ...

  4. 每日英语:Vender Assault Shines Ugly Light on China's Urban Enforcers

    The sudden death of a street vendor in Hunan province on Wednesday provoked outrage chengguan, or ur ...

  5. HADOOP 2.6 INSTALLING ON UBUNTU 14.04 (hadoop 2.6 部署到ubuntu 14.04上面)

    Hadoop on Ubuntu 14.04 In this chapter, we'll install a single-node Hadoop cluster backed by the Had ...

  6. PHP的数据类型转换

    PHP的数据类型转换属于强制转换,允许转换的PHP数据类型有: •(int).(integer):转换成整形 •(float).(double).(real):转换成浮点型 •(string):转换成 ...

  7. 应用DataAdapter对象填充DataSet数据集

    private void Form1_Load(object sender, EventArgs e) { string strCon = "Server=localhost;User Id ...

  8. Scala中集合类型与java中集合类型转换

    对于java中的集合元素并不能在scala中拿来就用的,需要进行相应的转换. 1. 转换规则如下 从下面可以看出,有些可以相互转换的,有些只能单向转换: scala.collection.Iterab ...

  9. 在MySQL应用上的挑战

    本期采访的讲师是来自腾讯高级软件工程师 雷海林,他有着10年以上的Linux后台Server开发经验,目前主要从事分布式Cache.实时大数据处理引擎,分布式MySQL(TDSQL)设计和开发工作. ...

  10. HeadFirst jsp 08 无脚本JSP

    web页面设计人员真的必须懂 java ? web页面人员可以很快学习 EL 语言. 目前不知道 EL 应用前景如何, 但是我们香港系统没有使用 EL. include 指令 include指令告诉容 ...