1. Map<String, String> map = new HashMap<String, String>();
  2. map.put("key1", "value1");
  3. map.put("key2", "value2");
  4. map.put("key3", "value3");
  5.  
  6. //第一种:普遍使用,二次取值
  7. System.out.println("通过Map.keySet遍历key和value:");
  8. for (String key : map.keySet()) {
  9. System.out.println("key= "+ key + " and value= " + map.get(key));
  10. }
  11.  
  12. //第二种
  13. System.out.println("通过Map.entrySet使用iterator遍历key和value:");
  14. Iterator<Map.Entry<String, String>> it = map.entrySet().iterator();
  15. while (it.hasNext()) {
  16. Map.Entry<String, String> entry = it.next();
  17. System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue());
  18. }
  19.  
  20. <span style="color:#FF0000;"> //第三种:推荐,尤其是容量大时</span>
  21. System.out.println("通过Map.entrySet遍历key和value");
  22. for (Map.Entry<String, String> entry : map.entrySet()) {
  23. System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue());
  24. }
  25.  
  26. //第四种
  27. System.out.println("通过Map.values()遍历所有的value,但不能遍历key");
  28. for (String v : map.values()) {
  29. System.out.println("value= " + v);
  30. }
  1. public class HashMapAdapter extends BaseAdapter {
  2.  
  3. private HashMap<String, String> mData = new HashMap<String, String>();
  4. private String[] mKeys;
  5. public HashMapAdapter(HashMap<String, String> data){
  6. mData = data;
  7. mKeys = mData.keySet().toArray(new String[data.size()]);
  8. }
  9.  
  10. @Override
  11. public int getCount() {
  12. return mData.size();
  13. }
  14.  
  15. @Override
  16. public Object getItem(int position) {
  17. return mData.get(mKeys[position]);
  18. }
  19.  
  20. @Override
  21. public long getItemId(int arg0) {
  22. return arg0;
  23. }
  24.  
  25. @Override
  26. public View getView(int pos, View convertView, ViewGroup parent) {
  27. String key = mKeys[pos];
  28. String Value = getItem(pos).toString();
  29.  
  30. //do your view stuff here
  31.  
  32. return convertView;
  33. }
  34. }

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. 1 - Reverse Integer

    Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321Discuss: 1. ...

  2. Mysql 逻辑运算符详解

    逻辑运算符又称为布尔运算符,用来确认表达式的真和假.MySQL 支持4 种逻辑运算符,如表4-3 所示. 表4-3                          MySQL 中的逻辑运算符 运算符 ...

  3. CentOS 删除桌面环境

    帮客户买了一个vps, 结果里面装了一堆没用的软件,所以全部删掉 CentOS 桌面安装大多都是 以软件包的 形式安装 所以 最好是设置好 国内的yum 源, 然后执行: >yum groupl ...

  4. ui-router详解(二)ngRoute工具区别

    我们了解 angular.js 是一种富客户端单页面应用,所以要在一个页面呈现不同的视图,路由起到了至关重要的作用. angular.js 为我们封装好了一个路由工具 ngRoute ,它是一种靠ur ...

  5. openWRT学习之LUCI之中的一个helloworld演示样例

    备注1:本文 讲述的是原生的openWRT环境下的LUCI 备注2:本文參考了诸多资料.感谢网友分享.參考资料: http://www.cnblogs.com/zmkeil/archive/2013/ ...

  6. 32位嵌入式微处理器(processor)一览

    32位嵌入式微处理器(processor)一览 由于嵌入式系统的专用型与定制性,与全球PC市场不同,没有一种微处理器或者微处理器公司可以主导嵌入式系统.本文分析了当前市场上主流的一些32位嵌入式微处理 ...

  7. Vim-复制选中内容至系统剪贴板,光标移动到指定行的行首和行尾

    1.全选并复制到系统剪贴板 ggVG或ggvG 然后 "+y gg 让光标移到首行,在vim才有效,vi中无效 V 是进入Visual(可视)模式 G 光标移到最后一行 "+y 复 ...

  8. Hystrix的原理与使用

    转载自:https://segmentfault.com/a/1190000005988895              http://blog.csdn.net/xiaoyu411502/artic ...

  9. 记一次有趣的 Netty 源码问题

    背景 起因是一个朋友问我的一个关于 ServerBootstrap 启动的问题. 相关 issue 他的问题我复述一下: ServerBootstrap 的绑定流程如下: ServerBootstra ...

  10. 如何利用wireshark对TCP消息进行分析

    原文:https://www.cnblogs.com/studyofadeerlet/p/7485298.html 如何利用wireshark对TCP消息进行分析   (1) 几个概念介绍 1 seq ...