• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

which map class is best for my need

 
ilias basha
Ranch Hand
Posts: 55
Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually i am engaged in a project where i need to hold three different values in a collection, in which two values are to treated as key and one flag value is value to the key.

And for me performance wise holding in which collection is better considering the speed of search, insert, delete etc..

and give reasons for why to use a particular class
 
Campbell Ritchie
Sheriff
Pie
Posts: 47228
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mean you want a class which encapsulates both keys, with correctly-overridden equals() and hashCode() methods, and use that as a "composite" key?

Go through the classes implementing Map, but for general purpose use, try HashMap.

If you can encapsulate the value in that class too, then you can use a HashSet.
 
ilias basha
Ranch Hand
Posts: 55
Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, i want to hold multiple keys against a single value(flag that needs to be updated) against a combination of key items.
 
ilias basha
Ranch Hand
Posts: 55
Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and if possible please give me which map class suits my needs better, as it should be faster in searching, insert, delete operations.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47228
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at the documentation for the different classes which implement Map; they tell you which is faster.

Do you mean have a mapping like this?

"Campbell" ---> 3
"Ilias" ---> 3

Yes, that is supported by the Map interface.
 
ilias basha
Ranch Hand
Posts: 55
Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Have a look at the documentation for the different classes which implement Map; they tell you which is faster.

Do you mean have a mapping like this?

"Campbell" ---> 3
"Ilias" ---> 3

Yes, that is supported by the Map interface.


can you give a brief code for that. and how to traverse within the map, i guess we cannot use iterator. any alternate.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47228
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ilias basha wrote:can you give a brief code for that. and how to traverse within the map, i guess we cannot use iterator. any alternate.
We expect you to be able to create your own code to test that. Read this FAQ.
Maps are not intended for traversal; the nearest you will get is this method, then use an Iterator on the resultant set.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic