Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes which map class is best for my need Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "which map class is best for my need" Watch "which map class is best for my need" New topic
Author

which map class is best for my need

ilias basha
Ranch Hand

Joined: Nov 27, 2008
Posts: 55

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

Joined: Oct 13, 2005
Posts: 38481
    
  23
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

Joined: Nov 27, 2008
Posts: 55

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

Joined: Nov 27, 2008
Posts: 55

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

Joined: Oct 13, 2005
Posts: 38481
    
  23
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

Joined: Nov 27, 2008
Posts: 55

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

Joined: Oct 13, 2005
Posts: 38481
    
  23
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: which map class is best for my need