从 ArrayList<HashMap<String, String>> 取值 [英] Take values from ArrayList&lt;HashMap&lt;String, String&gt;&gt;

查看:38
本文介绍了从 ArrayList<HashMap<String, String>> 取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在从 ArrayList> 获取值时遇到问题.

I have a problem about getting a value from my ArrayList<HashMap<String, String>>.

我的代码是:

ArrayList<HashMap<String, String>> myArrayList;

然后:

HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_ID, id);
map.put(TAG_NAME, name);
myArrayList.add(map);

例如,如果我想获取名称,我尝试了以下操作,但出现运行时错误(应用程序崩溃):

If I want to get the name, for example, I tried as follow but I obtain a runtime error (the application crashes):

System.out.println(myArrayList.get(1).get(TAG_NAME));

我该如何解决?

非常感谢!

推荐答案

System.out.println(myArrayList.get(1).get(TAG_NAME));

ArrayList 从 0 开始.get(0) 代替.

ArrayList is 0-based. get(0) instead.

这篇关于从 ArrayList<HashMap<String, String>> 取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆