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;
- }
- }
Map<String, String>的数据处理以及ListView的适配器的更多相关文章
- 入门:Java Map<String,String>遍历及修改
重点:在使用Map时注意key-value,key用于检索value的内容. 在正常情况下,可以不允许重复:在java中分为2中情况,一是内存地址重复,另一个是不同的地址但内容相等. 在使用Map是一 ...
- alibaba fastjson List<Map<String, String>>2Str
import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map; impo ...
- getParameterMap()的返回值为Map<String, String[]>,从其中取得请求参数转为Map<String, String>的方法如下:
直接遍历报错:[Ljava.lang.String;@44739f3f Map<String, String> tempMap = new HashMap<String, Strin ...
- JAVA/Android Map与String的转换方法
在Android开发中 Map与String的转换在,在一些需求中经常用到,使用net.sf.json.JSONObject.fromObject可以方便的将string转为Map.但需要导入jar包 ...
- FastJSON 简介及其Map/JSON/String 互转
在日志解析,前后端数据传输交互中,经常会遇到 String 与 map.json.xml 等格式相互转换与解析的场景,其中 json 基本成为了跨语言.跨前后端的事实上的标准数据交互格式.应该来说各个 ...
- 使用STL map 用 string 做索引 插入删除数据
1.代码 #include <map> #include <string> #include <stdio.h> #include <vector> # ...
- POJ2503——Babelfish(map映射+string字符串)
Babelfish DescriptionYou have just moved from Waterloo to a big city. The people here speak an incom ...
- JAVA中List转换String,String转换List,Map转换String,String转换Map之间的转换类
<pre name="code" class="java"></pre><pre name="code" cl ...
- Android List<Map<String,String>转json(例子)
package com.armslee.json.test.cases; import java.util.ArrayList; import java.util.HashMap; import ja ...
随机推荐
- 1 - Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321Discuss: 1. ...
- Mysql 逻辑运算符详解
逻辑运算符又称为布尔运算符,用来确认表达式的真和假.MySQL 支持4 种逻辑运算符,如表4-3 所示. 表4-3 MySQL 中的逻辑运算符 运算符 ...
- CentOS 删除桌面环境
帮客户买了一个vps, 结果里面装了一堆没用的软件,所以全部删掉 CentOS 桌面安装大多都是 以软件包的 形式安装 所以 最好是设置好 国内的yum 源, 然后执行: >yum groupl ...
- ui-router详解(二)ngRoute工具区别
我们了解 angular.js 是一种富客户端单页面应用,所以要在一个页面呈现不同的视图,路由起到了至关重要的作用. angular.js 为我们封装好了一个路由工具 ngRoute ,它是一种靠ur ...
- openWRT学习之LUCI之中的一个helloworld演示样例
备注1:本文 讲述的是原生的openWRT环境下的LUCI 备注2:本文參考了诸多资料.感谢网友分享.參考资料: http://www.cnblogs.com/zmkeil/archive/2013/ ...
- 32位嵌入式微处理器(processor)一览
32位嵌入式微处理器(processor)一览 由于嵌入式系统的专用型与定制性,与全球PC市场不同,没有一种微处理器或者微处理器公司可以主导嵌入式系统.本文分析了当前市场上主流的一些32位嵌入式微处理 ...
- Vim-复制选中内容至系统剪贴板,光标移动到指定行的行首和行尾
1.全选并复制到系统剪贴板 ggVG或ggvG 然后 "+y gg 让光标移到首行,在vim才有效,vi中无效 V 是进入Visual(可视)模式 G 光标移到最后一行 "+y 复 ...
- Hystrix的原理与使用
转载自:https://segmentfault.com/a/1190000005988895 http://blog.csdn.net/xiaoyu411502/artic ...
- 记一次有趣的 Netty 源码问题
背景 起因是一个朋友问我的一个关于 ServerBootstrap 启动的问题. 相关 issue 他的问题我复述一下: ServerBootstrap 的绑定流程如下: ServerBootstra ...
- 如何利用wireshark对TCP消息进行分析
原文:https://www.cnblogs.com/studyofadeerlet/p/7485298.html 如何利用wireshark对TCP消息进行分析 (1) 几个概念介绍 1 seq ...