| Author |
Check if ArrayList Contains a Map
|
Aditya Sirohi
Ranch Hand
Joined: Jan 05, 2010
Posts: 91
|
|
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
Joined: Jul 08, 2003
Posts: 24057
|
|
|
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?
|
[Jess in Action][AskingGoodQuestions]
|
 |
Javin Paul
Ranch Hand
Joined: Oct 15, 2010
Posts: 276
|
|
once you know that you have Map , get its keyset by map.keyset() and iterate through it print key and value.
|
http://javarevisited.blogspot.com - java classpath - Java67 - java hashmap - java logging tips java interview questions Java Enum Tutorial
|
 |
 |
|
|
subject: Check if ArrayList Contains a Map
|
|
|