Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

How we compare two maps in java

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My data present in list.That list is a value of MAP.same another MAP also containing list.Now i want to compare list values.How we compare list values of Map data structure. Please any one help me?
 
Greenhorn
Posts: 26
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Anitha,
Could you please post a code sample of the objects that you have to compare. The post doesnt seem to be that clear.

Thanks,
Raghav V
 
Anitha Kuchana
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am using struts with hibernate.in map code is key=1 value={place Code= 1001,place name= ""}and key=2 value={place code=1002 ,place name=""}....etc
And another map also having same values Now i want to compare the place code.how we compare this
 
Sheriff
Posts: 16948
286
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a common anti-pattern that I have the misfortune to see too many times. A map that contains maps that map object properties as key-value pairs. It's a very bad practice and rather than try to figure out the answer to your original question, I suggest you choose a different data structure. Java is an object-oriented language, so what you should have is, at the least, a List of objects that encapsulate the values of 'code', 'name', etc. and an implementation of equals() for that kind of object. Then you can use the built-in List methods to check if an element of one List has an equivalent element in another List.
 
Anitha Kuchana
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you for your answer .
can you give me the code for :convert map to list
please give a sample code ...?
example :
i am using struts with hibernate in my project.

Map<Integer, pojo name > oldMap = null;
Map<Integer, pojo name > newMap = null;

oldMap ={
1,values={list of objects that each object contains {place code="1001" placename="USA"}}
2,values={list of objects that each object contains {place code="1001" placename="USA"}...etc
}

similarlly

newMap={1,values={list of objects that each object contains {place code="1001" placename="USA"}}
2,values={list of objects that each object contains {place code="1001" placename="USA"}...etc
}


Now i want compare these place code of oldMap and newMap..

earlier you said convert map into list....
please give me the sample code.And how to convert from map into list?
And solution for the above situation?



 
Junilu Lacar
Sheriff
Posts: 16948
286
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, but this site is NotACodeMill (<--click). You'll have to ShowSomeEffort and give it your best shot to do it yourself. Since you're using Hibernate, you should read up on Object-Relational Mapping concepts and how to map (translate) relational data into objects. Hibernate can actually do a lot of the heavy lifting for you here.

Edit: missed the fact that you asked for examples. You can find examples in the Hibernate documentation: Start here: http://docs.jboss.org/hibernate/orm/ then choose the version of Hibernate that you're using, go to reference or manual or quickstart (depends on the version), then pick a language and format. Good luck.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Anitha Kuchana wrote:thank you for your answer .
can you give me the code for :convert map to list


Sure. Iterate through the Map "values", and then iterate through each value in its list, and add them to a standard List.

If you want better advice than that, then you'll have to give us a LOT more information about what it is you want to do. All you've described is the mechanics; and therefore you have a mechanical answer.

please give a sample code ...?


No...and I think Junilu's explained why.

Winston
 
Don't count your weasels before they've popped. And now for a mulberry bush related tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic