Topic
  • 2 replies
  • Latest Post - ‏2012-08-14T18:35:18Z by gr8yash
sobha
sobha
1 Post

Pinned topic HashMap Comparison

‏2007-06-20T13:55:39Z |
Hi,

I need to compare 2 hashmaps.If the values of same key in both hashmaps doesnt match, I need to display both the values.How do I extract these values and keys from a hashmap??
Any help would be greatly appreciated.

Thanks in advance,
Sobha
Updated on 2012-08-14T18:35:18Z at 2012-08-14T18:35:18Z by gr8yash
  • SystemAdmin
    SystemAdmin
    2768 Posts

    Re: HashMap Comparison

    ‏2007-06-21T04:06:33Z  
    HashMap.equals() will tell you if two maps are equal. (Check the API for more exact definition of how this works.)

    You can go through every Key-Value pair in the HashMap using the HashMap.entrySet() method to extract a reference to the actual Collection of "Map.Entry" objects.

    Use a Iterator to go through all of them, if you need to check each of the internal entries.
  • gr8yash
    gr8yash
    3 Posts

    Re: HashMap Comparison

    ‏2012-08-14T18:35:18Z  
    HashMap.equals() will tell you if two maps are equal. (Check the API for more exact definition of how this works.)

    You can go through every Key-Value pair in the HashMap using the HashMap.entrySet() method to extract a reference to the actual Collection of "Map.Entry" objects.

    Use a Iterator to go through all of them, if you need to check each of the internal entries.
    First iterate over hash map and compare object using equals() method. ReferHow to iterate a Map or HashMap?