0

I am not a java developer, and this is not my homework or something. 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.

6
  • what's the data type of rs? Commented Feb 12, 2013 at 6:47
  • 1
    please go through java arrays docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html Commented Feb 12, 2013 at 6:48
  • 1
    This does not look like Java for me, Is it javascript? Commented Feb 12, 2013 at 6:50
  • 3
    JAVA arrays does not store values in this format. It's JavaScript, JSON Commented Feb 12, 2013 at 6:50
  • 2
    Does not look like a java code to me. May be a javascript! Commented Feb 12, 2013 at 6:51

2 Answers 2

2

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. The first map named "pageParameters" is empty. The second one is named period and contains two items. The key "end" maps to the value "2013/11/5". The key "begin" maps to the value "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.

Sign up to request clarification or add additional context in comments.

3 Comments

for updating rs after processing begin and end date and creating new values from them, I used first periods.put(end, new_end); and periods.put(begin, new_begin); then updating rs.put(periods,periods) method but I think I did somewhere wrong cos it didnt work! could you help me to solve this too?
I have updated the answer with what I think you where asking for.
yes Its ok, thanks dude, I just missed "" on first parameters!
1

you can do like following:

rs[1][0] for the first

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.