gpt4 book ai didi

java - Java 中的 N 到 N 索引关系

转载 作者:行者123 更新时间:2023-11-30 04:34:58 25 4
gpt4 key购买 nike

Possible Duplicate:
Bidirectional multi-valued map in Java

我需要一个实现 N 对 N 关系的数据结构。像Map<Foo,Bar>之类的东西与电话:

getValues(Foo foo): Collection<Bar>
getValues(Bar bar): Collection<Foo>

以及通常的管理方法,例如:

removeKey(Foo)   [remove all the <Foo,X> entries]
removeValue(Bar) [remove all the <X,Bar> entries]

是否有一些我可以使用的库或者我应该实现它?谢谢

最佳答案

为什么不创建 2 个映射,每个映射都从键到值的集合:

Map<Foo, Collection<Bar>>Map<Bar, Collection<Foo>>

如果您希望可以创建一个类来包装它们(也许可以使用一些类型的泛型,以便您可以轻松地重用它)并提供您需要的方法

关于java - Java 中的 N 到 N 索引关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13719111/

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