aspose file tools*
The moose likes Beginning Java and the fly likes Check if ArrayList Contains a Map Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Check if ArrayList Contains a Map" Watch "Check if ArrayList Contains a Map" New topic
Author

Check if ArrayList Contains a Map

Aditya Sirohi
Ranch Hand

Joined: Jan 05, 2010
Posts: 93

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: 24187
    
  34

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: 281


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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Check if ArrayList Contains a Map