i am trying to get the complete parameter map from the request object and iterate over it.
here is the sample code
Map map = request.getParameterMap();
for(Object key : map.keySet()){
String keyStr = (String)key;
Object value = map.get(keyStr);
System.out.println("Key " + (String)key + " : " + value);
}
output
Key businessunit : [Ljava.lang.String;@388f8321
Key site : [Ljava.lang.String;@55ea0889
Key startDate : [Ljava.lang.String;@77d6866f
Key submit : [Ljava.lang.String;@25141ee0
Key traffictype : [Ljava.lang.String;@4bf71724
its evident from the output that the value object is an instance of String
now when i change my code to something like this
Map map = request.getParameterMap();
for(Object key : map.keySet()){
String keyStr = (String)key;
Object value = map.get(keyStr);
if(value instanceof String)
System.out.println("Key " + (String)key + " : " + (String)value);
}
it prints nothing but as per the previous output it should have printed the values and if i remove instanceOf check it gives ClassCastException. is this the expected behavior or i am doing something wrong here ?


Stringsomewhere (try usingjava.lang.Stringinstead ofStringto find out)? 2. Are you using the exact same values when running the two pieces of code? 3. Try usingString.valueOf(value)orvalue.toString()and see what happens. Hope it helps. – The Nail Dec 5 '11 at 7:34