This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Software Teaming: A Mob Programming, Whole-Team Approach and have Woody Zuill and Kevin Meadows on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

Check if Map contains an array as an entry value

 
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all


I have a Map which is dynamically generated and can contain strings, and array of strings as values.
keys are strings.
if i do map.get('key') where 'key' has a string value -it returns s tring value which is good.
but if 'key' has an array stored inside map as value , it returns first element of array.

I can use getArray() but in that case i should know if 'key' is an array or not and that is not possible.
so i want to check if map contains an array .

I want to do something like this-
map.get("key").getClass().isArray()
Ofcouse I tried this and it wont work because getClass() checks first element of Array.

 
Sheriff
Posts: 27522
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lucky J Verma wrote:I have a Map which is dynamically generated and can contain strings, and array of strings as values.
keys are strings.
if i do map.get('key') where 'key' has a string value -it returns s tring value which is good.
but if 'key' has an array stored inside map as value , it returns first element of array.


Not if it's a java.util.Map, it doesn't.

I can use getArray() but in that case i should know if 'key' is an array or not and that is not possible.
so i want to check if map contains an array .


No, java.util.Map doesn't have a getArray() method. Perhaps your "Map" is some other class? If so then you should tell us what it is, otherwise it's impossible to answer questions about it.
 
Lucky J Verma
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

It is actually an ParameterMap from spring-webflow.jar.


http://static.springsource.org/spring-webflow/docs/1.0.x/api/org/springframework/webflow/core/collection/ParameterMap.html
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic