简体   繁体   English

在Java中的哈希图中获取值

[英]Getting values in hash map in Java

I am not a java developer, and this is not my homework or something. 我不是Java开发人员,也不是我的作业。 I am just in need of getting the values of these parameters: end & begin. 我只需要获取这些参数的值:结束和开始。 this is what I have: 这就是我所拥有的:

rs = [{}, {end=2013/11/5, begin=2012/11/6}]

I am wonder if I could get values like this: 我想知道是否可以得到像这样的值:

rs[1].end
rs[1].begin

the source is: 来源是:

protected QueryParameters prepareForm(final ActionContext context) {
    final SearchErrorLogForm form = context.getForm();
    Map<String, Object> rs = form.getValues();
    System.out.println(rs);

    /*the output is: {pageParameters={}, period={end=2013/11/5, begin=2013/11/6}} */
}

sorry, the rs type is hashmap. 抱歉,rs类型是hashmap。

That is not a valid statement. 那不是有效的声明。

A proper way of assigning an array would be: 分配数组的正确方法是:

String dates[] = {"2013/11/5","2012/11/6"};
String start = dates[0];
String end = dates[1];

There is a excellent tutourial at oracle docs 甲骨文文档中有很棒的教程

Okay, that is a Map containing two Maps as it seems. 好的,这似乎是一个包含两个Map的Map。 The first map named "pageParameters" is empty. 第一个名为“ pageParameters”的映射为空。 The second one is named period and contains two items. 第二个称为句点,包含两个项目。 The key "end" maps to the value "2013/11/5". 键“ end”映射到值“ 2013/11/5”。 The key "begin" maps to the value "2013/11/6". 键“ begin”映射到值“ 2013/11/6”。

To access the objects in the map you could do like this: 要访问地图中的对象,您可以这样做:

final Map<String, String> period = (Map<String, String>) rs.get("period");
final String begin = period.get("begin");
final String end = period.get("end");

If you would like to change a value in the map period you will need to overwrite the already existing one: 如果要在映射期间更改值,则需要覆盖已经存在的值:

period.put("end", "NEW_END");
rs.put("period", period);

For further information, Oracle has great tutorials on Hashmaps. 有关更多信息,Oracle提供了有关Hashmap的出色教程

you can do like following: 您可以执行以下操作:

rs[1][0] for the first rs[1][0]首先

rs[1][rs[1].length-1] for the last rs[1][rs[1].length-1]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM