[英]How to access hashmaps inside an ArrayList originated from a database?
I have an ArrayList with a bunch of hashmaps. 我有一个带有一堆哈希图的ArrayList。 Each hashmap has the name and value of a column originated from a database.
每个哈希图都有一个源于数据库的列的名称和值。 How do I access the value of these columns?
如何访问这些列的值?
The Netbeans variable inspector shows me: Netbeans变量检查器向我显示:
avaliacaoList = (java.util.ArrayList) [{id_grade_curricular=5476, posicao=...
And the debugger presents me with the values below: 调试器为我提供以下值:
I need to iterate in the ArrayList, accessing each hashmap and his values. 我需要在ArrayList中进行迭代,访问每个哈希图及其值。 I tried many ways to iterate in this ArrayList, but I could not find a way to access the field id_grade_curricular (see orange arrow) of each "record".
我尝试了许多方法来迭代此ArrayList,但是找不到用于访问每个“记录”的字段id_grade_curricular (请参见橙色箭头)的方法。 Can someone help me to achieve this?
有人可以帮助我实现这一目标吗? Thanks.
谢谢。
I am assuming you have a list of hashmaps and that you absolutely do need it that way. 我假设您有一个哈希表列表,并且您确实确实需要这种方式。
for (HashMap h : avaliacaoList){
Object result = h.get("id_grade_curricular");
//do something
}
Instead of Object use whatever you are storing. 可以使用您存储的任何内容来代替Object。
Remember, the items in the ArrayList
are HashMaps
. 记住,
ArrayList
中的项目是HashMaps
。 You have to then actually access the key:value pair you want. 然后,您必须实际访问所需的key:value对。
for (HashMap entry : avaliacaoList){
int value = entry.get("id_grade_curricular")
// Do something with value here
}
Note here I'm assuming the type of the map is HashMap<string,int>
since that's what your example looks like. 请注意,这里我假设地图的类型是
HashMap<string,int>
因为这就是您的示例的样子。 Adjust the types accordingly if that's not true. 如果不正确,请相应地调整类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.