Link to home
Start Free TrialLog in
Avatar of ambuli
ambuliFlag for United States of America

asked on

Displaying contents of ConcurrentHashMap

Hi Experts,

 In the following code snippet, I am trying to print the values in the map.  How can I
properly iterate through the map.

Thanks
ConcurrentMap m_RequestQueue = new ConcurrentHashMap< String, QueueData>();
...
...
...  
 
 
public void displayQueues()
    {
        System.out.println("Request Queue:");
        Iterator it = m_RequestQueue.keySet().iterator();
       
        while (it.hasNext())
        {          
            QueueData reqData = (QueueData) it.next();  // cast exception
            reqData.printData();
        }
    }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Peter Kwan
Peter Kwan
Flag of Hong Kong image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ajay-Singh
Ajay-Singh

You can use this,
 
Map<String,String> map = new ConcurrentHashMap<String,String>();
for(Entry<String, String> entry: map.entrySet()) {
   String key = entry.getKey();
   String value = entry.getValue();
}