I'm using a TreeMap
to store sorted information. Both the keys and the objects indexed by them are of type String
. But, what I really want is a mapping that's "symmetrical". By this I mean I can get()
either object (ie String
) from the map by using the other one as a key. I'd still like it to be sorted by one of the objects. Does such a mapping structure exist? FWIW, there are no duplicate pairs in the data.
You can create a symmetrical mapping by adding the keys to the TreeMap
symmetrically:
map.put(a, b);
map.put(b, a);
This isn't exactly a special data structure, but it sounds like it would meet your requirements.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.