大家好,欢迎来到IT知识分享网。
 
ArrayList 与 LinkedList的效率实践分析
但是不经过验证如何说明问题。本文将会对ArrayList和LinkedList的插入、查询、删除进行实验,通过实验得到的数据来说明性能问题
 / * Inserts the specified element at the specified position in this * list. Shifts the element currently at that position (if any) and * any subsequent elements to the right (adds one to their indices). * * @param index index at which the specified element is to be inserted * @param element element to be inserted * @throws IndexOutOfBoundsException {@inheritDoc} */ public void add(int index, E element) { rangeCheckForAdd(index); ensureCapacityInternal(size + 1); // Increments modCount!! System.arraycopy(elementData, index, elementData, index + 1, size - index); elementData[index] = element; size++; } 
而LinkedList采用链表,则不存在移动元素的问题,只是会新建节点并修改相关引用。
 public void add(int index, E element) { checkPositionIndex(index); if (index == size) linkL
                                                        免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/120065.html