gpt4 book ai didi

Java 集合 - 唯一键和唯一值

转载 作者:IT老高 更新时间:2023-10-28 21:12:21 31 4
gpt4 key购买 nike

我需要一个可以根据键查找值的集合,反之亦然。每个值都有一个键,每个键都有一个值。是否有现成的数据结构可以做到这一点?

最佳答案

BiMap来自 Google Guava看起来很适合你。

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.

BidiMap来自 Apache Commons Collections :

Defines a map that allows bidirectional lookup between key and values.

This extended Map represents a mapping where a key may lookup a value and a value may lookup a key with equal ease. This interface extends Map and so may be used anywhere a map is required. The interface provides an inverse map view, enabling full access to both directions of the BidiMap.

关于Java 集合 - 唯一键和唯一值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/711618/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com