Take the 2-minute tour ×

The situation is as follows:


How can this be retrieved in an array in Java?

The following:


I know can be retrieved using request.getParameterValues("var")

Any solutions for the above though?

share|improve this question
Does it have to be in a GET request? –  Mike Pone May 13 '09 at 20:16
No, it can be POST or GET, as long as it's retrievable via the request object. –  adnan. May 14 '09 at 12:50

2 Answers 2

up vote 4 down vote accepted
Map<Integer,String> index2value=new HashMap<Integer,String>();

for (Enumeration e = request.getParameterNames(); e.hasMoreElements() ;)
 String param= e.nextElement().toString();
 if(!param.matches("var\[[0-9]+\]")) continue;
 int index= (here extract the numerical value....)

Hope this helps.

share|improve this answer
I was hoping there would have been a more "automatic" way. But this will have to do. Thanks. –  adnan. May 15 '09 at 19:02
HashMap m = request.getParameterMap();
Set k = m.keySet();
Set v = m.entrySet();
Object o[] = m.entrySet().toArray();

That will get you a Map call m with K,V pairs and both a set of keys and set of values. You can iterate those sets almost like an array. You can also use toArray to turn it into an array.

share|improve this answer

Your Answer


