Code Comments
Programming Forum and web based access to our favorite programming groups."James J. Gavan" <jgavandeletethis@shaw.ca> wrote in message news:uJNPf.128728$B94.114109@pd7tw3no... > > Can't have a duplicate Key in a collection anymore than you can have a > duplicate key in a COBOL file. Try to add an element creating a duplicate > key - it just gets ignored. I can have : > > Key---> then Data > ----------------- > 12345 Micro Focus Ltd > 12347 Micro Focus Ltd > > but I can't have : > > Micro Focus Ltd 12345 > Micro Focus Ltd 12347 > > Wasn't too clear about your reference to Pairs - but the following example > from Adele Goldberg (Smalltalk 80) is allowable to find 'Opposites' from > the Key :- > > Key---> then Data > ----------------- > hot cold > push pull > stop go > come go > front back > top bottom > > I think 'Pairs' you are possibly referring to something slightly different > ? Yes, I meant something different. In Java as well, you can't have a dictionary (though it's called a "Map" in Java) where two objects have the same key. I was saying you could "fake" it by having a "Pair" object whose sole purpose is to contain references to the two objects you *do* want to store. Key --> Data 123 (Hot, Cold) 124 (push, pull) 125 (stop, go) etc. The idea is that only one object, the "pair" object, is associate with a given key. But the pair object is like a collection whose size is guaranteed to always be 2. Obviously, you can extend this idea if you wanted to simulate 3 objects per key: Key --> Data 123 (Hot, Warm, Cold) 124 (push, rest, pull) 125 (red, green, blue) etc. - Oliver
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.