在 map 中我们有键值对。如果我们尝试在 map 中放置相同的键 2 次,它会产生错误。现在我也想要类似的值行为。简而言之,当我放置一个新的键值时进入 map 的键和值都应该是唯一的,否则应该通过异常, 我怎样才能做到这一点?
最佳答案
A bimap (or "bidirectional map") is a map that preserves the uniqueness of its values as well as that of its keys. This constraint enables bimaps to support an "inverse view", which is another bimap containing the same entries as this bimap but with reversed keys and values.
(顺便说一句,Guava 总体上是一个很棒的库。非常值得使用。)
关于java - 映射所需的行为类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3477183/