作者jgpnsgm (哼!)
看板java
标题Re: ArrayList 的用法怎麽跟其他物件没有一致性呢
时间Sat Jun 10 20:04:19 2006
※ 引述《dosiris (dosiris)》之铭言:
: 发现 ArrayList 的物件用法很特别
: 还要 ArrayList<String> xxx 才能建构带有 String 的 ArrayList
: 不像一般 Array 的建构 只要 string[] xxx 就可以
: 但这不就代表语法上不一致吗? 这样并不是很漂亮的感觉
: 纯粹个人看法 (搞不懂前者的使用为什麽要这样独树一格...)
http://java.sun.com/docs/books/tutorial/collections/index.html
没有必要一致,ArrayList属於Collections中的成员
和Array是不同的东西,也复杂得多
Collections 分为Set, List, Queue, Map几个基本的interfaces
有不同的功能,但都可以使用Collections中的method(ex: sort,shuffle,binarysearch)
其中List又分为 ArrayList, LinkedList
虽然操作介面一致但实作方式不同
ArrayList在random access比LinkedList快... O(1):O(n)
而LinkedList在insert element就比ArrayList快... O(1):O(n)
总之Array的结构简单,但是要做一些处理时可能要自己写code
Collections结构复杂(其实一般user碰不到,要用还蛮简单的),
但有一致的操作介面以及一些预设的功能。
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.111.79.32