Understand ArrayList and linkedlist differences from source code
ArrayList
ArrayList Default Capacity is ten, the essence is an array to hold the element,size represents ArrayList The number of elements that are contained.
ArrayList 3 Constructors, the first constructor specifies the capacity, the second constructor defaults to an empty array, and the third constructor changes from set C to array of Arraylist
Add function, first confirm that the array capacity is not enough, at first if the default initialization (that is, call the second constructor), add the element when the grow out of the array capacity of ten, Construct a new array and copy The value of the original array element, then element[0] assignment, the second time the element is added because elementdata! = Empty_ Elementdata and
Mincapacity-elementdata.length <0 so direct element[1] assignment, and does not expand capacity, only when full capacity will be expanded.
The Remove (int ) function, which moves the elementwith the ordinal index ,nummoved refers to the number of elements after index , The element behind the system.arraycopy pushes forward one cell , and the last element is null, returning the deleted value
the same principle as remove (int) above .
Returns the ordinal if it is found, otherwise returns -1
LinkedList
LinkedList Storage data is stored in the form of a chain list
first is pointing to the top node and last is pointing to the tail junction.
LinkedList has two constructors, and the second constructor passes the elements of the collection to the linked list
is a way to insert data using a linked list
Are all methods of deleting elements using a linked list
The method by which the linked list looks for elements.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
From the source to understand ArrayList and LinkedList differences