Two Laptop Bag
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Check if ArrayList Contains a Map" Watch "Check if ArrayList Contains a Map" New topic

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 :-
{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:-
key: default / value: [key, bundleX]

Suggestions are appreaciated.
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

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

once you know that you have Map , get its keyset by map.keyset() and iterate through it print key and value.

SQL Query Interview Question java67 Javarevisited
I agree. Here's the link:
subject: Check if ArrayList Contains a Map
It's not a secret anymore!