This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: 37926
    
  22
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: 37926
    
  22
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: 37926
    
  22
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: which map class is best for my need
 
Similar Threads
How to store two similar values
html:iterator troubles
Is there a Properties-like class that allows multiple values per key?
Need collection
Duplicate check in colection