posted 8 years ago
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
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
posted 8 years ago
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.
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.
Campbell Ritchie
Sheriff
Posts: 57845
178
posted 8 years ago
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 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
Posts: 57845
178
posted 8 years ago
Maps are not intended for traversal; the nearest you will get is this method, then use an Iterator on the resultant set.
We expect you to be able to create your own code to test that. Read this FAQ.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.
Maps are not intended for traversal; the nearest you will get is this method, then use an Iterator on the resultant set.

It is sorta covered in the JavaRanch Style Guide. |