Map<String, String>的数据处理以及ListView的适配器

  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;
    }
}
时间: 2024-10-13 22:51:37

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

HDU 1113 Word Amalgamation (map 容器 + string容器)

http://acm.hdu.edu.cn/showproblem.php?pid=1113 Problem Description In millions of newspapers across the United States there is a word game called Jumble. The object of this game is to solve a riddle, but in order to find the letters that appear in th

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

Babelfish DescriptionYou have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language. Fortunately, you have a dictionary to help you understand them.InputInput consists of up to 100,000 diction

List&amp;lt;Map&amp;lt;String, String&amp;gt;&amp;gt; 开启 Map&amp;lt;String, List&amp;lt;String&amp;gt;&amp;gt;

将List变成Map结构体,下面的文字是没有水平! 写作方法传送前土壤很长一段时间.我不知道有没有好的解决办法.我们也希望提供! Map<String, String> map1 = new HashMap<String, String>(); map1.put("a", "1"); map1.put("b", "3"); map1.put("c", "5");

Struts2标签遍历List&lt;Map&lt;String, String&gt;&gt;

import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import com.opensymphony.xwork2.ActionSupport; public class LoginAction extends ActionSupport { private List<Map<String, String>> list; @Override

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

在日志解析,前后端数据传输交互中,经常会遇到 String 与 map.json.xml 等格式相互转换与解析的场景,其中 json 基本成为了跨语言.跨前后端的事实上的标准数据交互格式.应该来说各个语言中 解析 json 的库都一大片(具体 json 格式与三方库的介绍请见:http://www.json.org/json-zh.html),比如 python 都集成在了内置库中,成为标准 API,今天我们要聊的是 java 中如何方便的使用 json 格式. 从上面的链接介绍中我们可以看到,

Babelfish (map 用法。&lt;string, string&gt;

Babelfish - You have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language. Fortunately, you have a dictionary to help you understand them. Input Input consists of up to 100,000 dictionary ent

Map&lt;String,List&lt;String&gt;&gt;转为List&lt;Map&lt;String,String&gt;&gt;

/**  *   * @param map  输入  * @param list 输出  * @param idx     次序  * @param pathMap 已选  */ void map2List(Map<String, List<String>> map, List<Map<String, String>> list,                                     int idx, HashMap<String,S

JSON详解+ C# String.Format格式说明+ C# ListView用法详解 很完整

JSON详解 C# String.Format格式说明 C# ListView用法详解 很完整

hdu1113 Word Amalgamation(超详细解释--map和string的运用)

转载请注明出处:http://blog.csdn.net/u012860063天资 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1113 来吧!!欢迎"热爱编程"的同学报考杭电,期待你加入"杭电ACM集训队"! 7月22-8月21多校联合训练期间,会根据实际负载关闭部分模块,若有不便,请谅解~ Word Amalgamation Time Limit: 2000/1000 MS (Java/Others)    Me