0

I have a defined group of 5 Parkings. I receive from a poll server every 20 seconds new values of these parkings(Id, Number of available places, etc)

I am wondering which java collection, in terms of performance and "best practices" allows me to keep only my 5 parkings at a time and not having duplicated parkings and then to retrieve a parking by Id.

Thanks in advance.

4

1 回答 1

0

假设没有重复的Id键,那么Map接口的任何标准实现都可以。您可以通过键检索值,为现有键插入值将替换旧值,因此不存在重复键。

也就是说,这HashMap是标准Map实现中性能最高的,前提是您唯一的要求是防止重复密钥。LinkedHashMap此外,它还提供了具有可预测顺序的迭代,而对性能的影响很小。TreeMap具有更高的复杂性,因此性能较低,但它会不断地根据它们的键对所有条目进行排序。

于 2014-05-21T23:30:45.517 回答