• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Check if ArrayList Contains a Map

 
Aditya Sirohi
Ranch Hand
Posts: 93
Eclipse IDE Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Folks,

I have the following snippet of code:-



The output of this program is :-
Hello
World
{default=[key, bundleX]}

Is there a way i can detect if this ArrayList contains a Map and if it does can i get the key/value pair? Output like this:-
Hello
World
key: default / value: [key, bundleX]


Suggestions are appreaciated.
Thanks
Aditya
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Inside your "for" loop, you can just retrieve a value from the list, check if it's a map using "instanceof", and if so, print your special case output. Are you looking for something more obscure?
 
Javin Paul
Ranch Hand
Posts: 295
Eclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

once you know that you have Map , get its keyset by map.keyset() and iterate through it print key and value.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic