从运行结果来看,删除时linklist要比arraylist快,但添加的时候arraylist要快了不少啊
哪位高人帮小弟分析一下,谢谢

解决方案 »

  1.   

    都说LinkList 添加,删除速度快.并不是说依次添加快.
    ArrayList类add方法开销为分摊的常数,添加n个元素需要O(n)的时间。
    而LinkList是链表他如果在中间操作将占优势.
      

  2.   

    As expected, array are faster than any container for random-access lookups and iteration. You can see that randomaccess(get())are cheap for ArrayList and expensive for LinkedLists. (Oddly, iteration is faster for a LInkedList than an ArrayList, which is a bit counterintuitve) On the other hand, insertion and removals from the middle of a list are dramatically cheaper ofr a LinkedList than for an ArrayList--especially removes.--<Thinking in JAVA>, 3rd Edtion. P554
      

  3.   

    ArrayList是List接口的一个可变长数组实现。实现了所有List接口的操作,并允许存储null值。除了没有进行同步,ArrayList基本等同于Vector。在Vector中几乎对所有的方法都进行了同步,但ArrayList仅对writeObject和readObject进行了同步,其它比如add(Object)、remove(int)等都没有同步。 
      

  4.   

    你添加是顺序添加的,当然是ArrayList要快,但是如果随机添加删除中间元素,肯定是LinkedList快。
      

  5.   

    大家说完了,我也重复一下,哈哈
    搂主没有认真看看文档,文档中说,在对多条记录中进行插入,删除LinkList比ArrayList快,按顺序的话是ArrayList快。