This week's book giveaway is in the Design forum.We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!

# TreeMap question

Jacob Sonia
Ranch Hand
Posts: 183
I have a TreeMap

The keys in the TreeMap are:
iu_1
pu_1
dbu_1
ru_1
iu_3

etc.
The number index is not fixed and can change.

So, i want to know if my TreeMap contains more than one value with same number index, like iu_1 and pu_1 have the same index, if so i want to add some error codes.

One way to find this is to iterate the whole map and then check for each key's number index and see if it is equal to the previous one.

Thanks

Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
I want you to know about how HashMap/TreeMap works? and you may require to know about hashing techniques!

Luigi Plinge
Ranch Hand
Posts: 441
What you are trying to do is quite unusual, so there's nothing built-in to do this. I'd do something like

Jacob Sonia
Ranch Hand
Posts: 183
Thanks,
This looks good.

Luigi Plinge
Ranch Hand
Posts: 441
Incidentally I was playing aroud with this earlier. If you learn Scala, you can do fun stuff like to get a map of the duplicated indicies to the keys containing them.

E.g. for the above example the string value of duplicates is Map(2 -> Set(dbu_2, iu_2)) (only 1 element, but if there were more duplicates there would be more).

Scala might look a bit cryptic but it's pretty simple once you know that _ is the wildcard, standing for each element of the collection.