简体   繁体   English

在 Java 中创建一个 ArrayList 来存储 HashSet

[英]Create an ArrayList to store HashSet in Java

I have an array of nodes, which is 4000 elements large.我有一个节点数组,它有 4000 个元素。 During my traversal algorithm, each node will meet other node.在我的遍历算法中,每个节点都会遇到其他节点。 I want to create a HashSet to store each node it meets on the way.我想创建一个HashSet来存储它在途中遇到的每个节点。 Each node should has their own HashSet .每个节点都应该有自己的HashSet

Does Java have a construct like this? Java 有这样的构造吗?

<Hashset<Node>>[] res = new Hashset<Node>[4000];

Yes.是的。 A generic type parameter may itself be generic , and thus the following is valid: 泛型类型参数本身可能是 generic ,因此以下内容是有效的:

ArrayList<HashSet<Node>> res=new  ArrayList<HashSet<Node>>();

Note capitalization in the name of java.util.HashSet .注意java.util.HashSet名称中的大写。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM