[英]What's the right Java generic for a collection of elements with unique addressable indices?
I'm on my way to programming a database application and in our course we are told to implement a library of elements using one of the Java Collections. 我正在对数据库应用程序进行编程,在我们的课程中,我们被告知要使用其中一个Java集合来实现元素库。 Each of the elements has a unique ID with which it's supposed to be addressed. 每个元素都有一个唯一的ID,应该使用该ID进行寻址。 Now I am wondering how this can be done. 现在我想知道如何做到这一点。
I though about using a ListArray but this won't work because the only way of addressing List elements is through the index which you can't control. 我虽然要使用ListArray,但是这行不通,因为寻址List元素的唯一方法是通过无法控制的索引。
Do you have some advice for me? 你对我有什么建议吗?
Map<IndexType, YourEntityType>
. Map<IndexType, YourEntityType>
。 Map
is an interface; Map
是一个接口; the most commonly used implementation is HashMap
. 最常用的实现是HashMap
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.