siwei115 2010-05-18 15:12
浏览 274
已采纳

集合类的相关问题

Vector 与ArrayList  

Enumeration与Iterator

Collection与Set,List还有Hashtable类

 

 

想了解它们!

  • 写回答

1条回答

  • 拽拽的初行者 2010-05-18 15:58
    关注

    Vector 与ArrayList 都是基于数组实现的链表,大小可以自动扩展。不同点是,Vector是在1.0就有的,在1.2的时候,经过改进加入了Java Collection Framework中。而ArrayList是1.2的时候引入的。

    vector是同步的,ArrayList不是同步的。
    [b]
    Enumeration与Iterator[/b]

    Iterator的说明:
    [quote]对 collection 进行迭代的迭代器。迭代器取代了 Java Collections Framework 中的 Enumeration。迭代器与枚举有两点不同:

    迭代器允许调用者利用定义良好的语义在迭代期间从迭代器所指向的 collection 移除元素。
    方法名称得到了改进。 [/quote]

    Enumeration的说明
    [quote]注:此接口的功能与 Iterator 接口的功能是重复的。此外,Iterator 接口添加了一个可选的移除操作,并使用较短的方法名。新的实现应该优先考虑使用 Iterator 接口而不是 Enumeration 接口。 [/quote]

    两者的差异,API中说的很清楚了。其实也是在1.2引入Java Collections Framework时做的变化。

    [quote]Why doesn't Iterator extend Enumeration?
    We view the method names for Enumeration as unfortunate. They're very long, and very frequently used. Given that we were adding a method and creating a whole new framework, we felt that it would be foolish not to take advantage of the opportunity to improve the names. Of course we could support the new and old names in Iterator, but it doesn't seem worthwhile.
    [/quote]

    官方的解释,利用1.2改变之际,引入了Iterator 。

    [b]Collection与Set,List
    [/b]
    这3个是接口。 set list 均继承自collection,分别对应于数据结构中的集合、链表。

    hashtable是一个1.0引入的类。。。。看API吧。

    罗嗦了这么多,其实也没说出来什么内容。这里里面牵涉的最多的是1.0到1.2的变革。这也是Java2的来源之一吧,呵呵,臆断。

    使用的时候,尽量使用1.2后引入的,不要使用1.0就有的那些。因为API上是这样说的。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式