使用什么数据结构?

发布于 2024-10-02 15:36:21 字数 804 浏览 6 评论 0 原文

我需要存储以下数据;

Clampls = {"23e23e", "ff333g", "fhgswq"," h65h3", "ffwwf", "34rf3"}
KJAS3.2 = {"f34f4f", "43rf2d", "3rfas1"," 1122d", "fff42", "ff33f"}
...

我正在考虑将其存储为类似

 Name        Tokens
  .       -> ... , ... , ... , ...
  .       -> ... , ... , ... , ...
Clampls   -> "23e23e" , "ff333g" , "fhgswq" , ... 
KJAS3.2   -> "f34f4f" , "43rf2d" , "3rfas1" , ...  
  .       -> ... , ... , ... , ...
  .       -> ... , ... , ... , ...

HashMap 的东西。我在我的书《数据结构与数据结构》中读了一些内容。 Java 算法、R. Lafore 和我找到了我需要的东西,即单独的链接/哈希链,但是他们使用自己构建的数据结构类来解释它。

是否有一个可以在 java 中使用的 HashChain 的“现成”集合?像这样的东西

Map<String, []String> theMap = new HashMap<String, []String>(); //just an example

I need to store the following data;

Clampls = {"23e23e", "ff333g", "fhgswq"," h65h3", "ffwwf", "34rf3"}
KJAS3.2 = {"f34f4f", "43rf2d", "3rfas1"," 1122d", "fff42", "ff33f"}
...

I was thinking of storing it something like this

 Name        Tokens
  .       -> ... , ... , ... , ...
  .       -> ... , ... , ... , ...
Clampls   -> "23e23e" , "ff333g" , "fhgswq" , ... 
KJAS3.2   -> "f34f4f" , "43rf2d" , "3rfas1" , ...  
  .       -> ... , ... , ... , ...
  .       -> ... , ... , ... , ...

So sort of like a HashMap. I did some reading in my book Data Structures & Algorithms in Java, R. Lafore and i found what i need which is Separate Chaining / HashChain however they explain it using own built data structure classes.

Is there a "ready made" collection for a HashChain that i can use in java? Something like

Map<String, []String> theMap = new HashMap<String, []String>(); //just an example

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

緦唸λ蓇 2024-10-09 15:36:21
Map<String, List<String>> dataStructure = new HashMap<String, List<String>>();

dataStructure.put("Clampls", Arrays.asList("23e23e", "ff333g", "fhgswq"," h65h3", "ffwwf", "34rf3"));
dataStructure.put("KJAS3.2", Arrays.asList("f34f4f", "43rf2d", "3rfas1"," 1122d", "fff42", "ff33f"));

dataStructure.put("KJAS3.3", new ArrayList<String>());
dataStructure.get("KJAS3.3").add("fhgswq");
Map<String, List<String>> dataStructure = new HashMap<String, List<String>>();

dataStructure.put("Clampls", Arrays.asList("23e23e", "ff333g", "fhgswq"," h65h3", "ffwwf", "34rf3"));
dataStructure.put("KJAS3.2", Arrays.asList("f34f4f", "43rf2d", "3rfas1"," 1122d", "fff42", "ff33f"));

dataStructure.put("KJAS3.3", new ArrayList<String>());
dataStructure.get("KJAS3.3").add("fhgswq");
思念满溢 2024-10-09 15:36:21

你的问题不太清楚,所以这个答案可能是错误的。如果您希望给定键有多个值,则应使用 MultiMap。 JDK 中没有实现,但公共库中有很多实现,例如 Google Guava(包含以前的 Google Collections)。

Map> 这样的替代方案可以工作,但使用起来很尴尬,例如,如果键不存在,您必须自己创建“内部”列表。

Your question isn't very clear, so this answer could be off. If you want to have several values for a given key, you should use a MultiMap. There isn't an implementation in the JDK, but plenty of them in common libs, e.g. Google Guava (contains former Google Collections).

Alternatives like Map<String,List<String>> work, but are awkward to use, e.g. you have to create the "inner" List yourself if a key doesn't exist.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文