public boolean equals (Object o) {
if (o = = this)
return true;
if (! ( o instanceof List))
return false;
listiterator<e> e1 = Listiterator ();
listiterator<?> e2 = ((list<?>) O). Listiterator ();
while (E1.hasnext () && e2.hasnext ()) {
E O1 = E1.next ();
Object O2 = E2.next ();
if (! ( O1==null? O2==null:o1.equals (O2)))
return false;
}
Return! (E1.hasnext () | | e2.hasnext ());
}
This method is used to determine whether the two list is equal.
First, determine if the parameter and the same object referenced by this list directly return true. If the parameter does not belong to the implementation class of the list interface, it returns false directly.
Then get the parameter and the list iterator for the list, where the generic of the parameter's list iterator is? In other words, the generic type of the list iterator is the element type.
It then iterates through the two lists, gets each of the individual elements, determines in turn whether it is empty, and if not equal, returns false.
Never returns False if the two list can be iterated, and if one can iterate, it returns false, and two returns true if it is not iterated. | Both sides must be false, the entire expression will be false, the left side is true, it will short-circuit ...
public int hashcode () {
int hashcode = 1;
for (E e:this)
Hashcode = 31*hashcode + (e==null? 0:e.hashcode ());
return hashcode;
}
This method is the method that returns the hash value.
First define the initial hash value of 1, then traverse all the elements of the list, multiply the initial hash value by 31, plus the hash value of each element, and if the element is empty add 0, assign the calculated value to the initial hash value, and then cycle ...
Finally, the hash value is returned.
protected void RemoveRange (int fromIndex, int toindex) {
Listiterator<e> it = Listiterator (FromIndex);
for (int i=0, n=toindex-fromindex; i<n; i++) {
It.next ();
It.remove ();
}
}
This method is the way to delete elements within an interval.
First, the list iterator is obtained, the starting iteration position is the first parameter, and then the For loop is entered, looping the elements contained in the interval to be deleted, and then removing the elements with iterators.
Private String outofboundsmsg (int index) {
Return "Index:" +index+ ", Size:" +size ();
}
This method returns an error message that, when the operation is marked, indicates that the subscript is out of bounds.
Common learning Java source code--Data structure--abstractlist abstract class (iii)