arraylist: The money of the structure is understood, ArrayList () constructs an empty list of initial capacity =10, and the addition and deletion of ArrayList () is a copy of the array to the new array (if the current array is insufficient) to move the elements in the array forward/ Move back to finish, then point the reference to the new array; LinkedList () is to delete the reference node directly, and re-change the reference to the front and back elements of the node, ArrayList () can quickly find the corresponding element by subscript; thread synchronization, The same ArrayList is not a thread-safe list, like LinkedList; ArrayList () expansion is 1.5 times times the capacity of the current volume (write dead in the source):/*** increases the capacity to ensure It can hold at least the* number of elements specified by the minimum capacity argument.** @param mincapacity the desired Minimum capacity*/private void grow (int mincapacity) {//overflow-conscious codeint oldcapacity = Elementdata.length;int Newcapacity = oldcapacity + (oldcapacity >> 1); if (newcapacity-mincapacity < 0) newcapacity = mincapacity;if (NE Wcapacity-max_array_size > 0) newcapacity = hugecapacity (mincapacity);//mincapacity is usually close to SIZE is a win:elementdata = arrays.copyof (Elementdata, newcapacity);} Right Shift,>> is the right shift operator, NUM >> 1, which is equivalent to num divided by 2int newcapacity = oldcapacity + (oldcapacity >> 1); This is equivalent to 1.5 times times; hashcode ()and Equals (): To now only use Equals, used Hashcode;hashcode () and equal () and = =, in Java to compare the two objects are equal; = = is a comparison of the reference address (the variable is equal) The equal is the contrast value (the comparison object is equal, the default equals = =, is also the address of the comparison object, but compared to the object content is not equal to = =); Hashcode is the selects value (return hash value, if two objects are equal, then their hash value must be the same) ; If two objects are not equal according to the Eqaul () method, the resulting hashes are not necessarily equal (in the case of collisions); but one thing: the equal () of the rewrite is generally more complex in comparison, so the efficiency is relatively low, and the use of hashcode () to compare, Then just generate a hash value to compare it, the efficiency is very high, then hashcode () since the efficiency is so high why should equal () it? Because Hashcode () is not completely reliable, sometimes different objects will generate the same hashcode (generate hash is worth the problem of the formula), so Hashcode () can only say that most of the time reliable, not absolutely reliable; 1.equal () equal to two objects their hashcode () are certainly equal, i.e. with equal () The contrast is absolutely reliable. 2.hashcode () equal to two objects their equal () are not necessarily equal, i.e. hashcode () is not absolutely reliable.
Java Foundation-arraylist