Use standard Collections

本文探讨了集合框架中各种实现类的选择与性能优化策略,包括ArrayList、LinkedList、HashMap、HashSet、ArrayDeque等,强调了避免使用具有不确定迭代顺序的古老实现类如HashMap和HashSet,推荐使用TreeSet和TreeMap来保持元素的排序。文章还提到了在图形用户界面中使用这些类以保留项目操作的排序。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

In the  Collections Framework , there are many implementation classes to choose from. Most of the time, one of these "primary implementations" is the appropriate choice

Before JDK 1.5, HashMap and HashSet were the preferred implementations of Map and Set. However, the iterators returned by those classes have the somewhat bizarre property of having an undefined order. That is, iterating over a HashMap or HashSet can return elements in a different order at different times. Their iteration order is not guaranteed to be repeatable (and often isn't). Even though HashMap and HashSet have slightly better overall performance, for most business applications it is likely best to avoid such undefined behavior.

To retain the sorting of items being manipulated in a graphical user interface, TreeSet and TreeMap are useful. They force a collection to maintain a sort order when the user adds and deletes items. 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值