The following are just some important points:
- If the list length exceeds
Integer.MAX_VALUE
If so, returnInteger.MAX_VALUE
.
- If the list is not allowed to include
null
Element, ifo
fornull
, then throwNullPointerException
.
toArray
Method returns an array without an internal reference to the list.
toArray
In:
- If the runtime type of the array passed is not
list
When the corresponding parent class is thrownArrayStoreException
. - If the array passed meets the requirements at runtime, but the array length is greater than the number of elements in the list, all the excess is set to
null
. - If the specified array is
null
Is thrownNullPointerException
. - If the specified array length is less than the list length, a new array of all elements in the list is returned, leaving the array as it is passed in.
The other thing to notice is, two
toArray
Method, although the reference list of the array does not hold, the elements in the array are a reference to the elements in the list. Therefore, changing an attribute of an element in the array changes the attribute of the corresponding element in the list. However, if you change the reference of an element in the array, for examplea[0] = new MyObj()
This does not affect the list internal data, after all, this is the array ‘properties’ change, not the list
add
If the list is rejectednull
Element is addednull
Element is thrownNullPointerException
.
remove
Method removes the element with the lowest index.
addAll
Method if the specified collection is modified during an operation, the action is undefined (e.ga.addAll(a)
, that is, when the set adds itself, the parameter A also changes at the same time. At this time, the result is unknown. Of course, there are many other cases.)
In AbstractList (ArrayList superclass), is the specific manifestation of the undefined throws a ConcurrentModificationException.
removeAll
false
true
retainAll
true
false
replaceAll
equals
true
false
hashCode
31*hashCode
data
31 = (2 < < 4) - 1
add(index,obj)
remove(index)
indexOf(obj)
- If the list is allowed to exist
null
If the elements:obj==null
, you findnull
Element index, returns -1 if it does not exist, returns -1 if it doesnull
Element subscript. - If the list cannot exist
null
If the elements:obj==null
, then throwNullPointerException
. - if
obj! =null
To return toobj
The correspondingThe minimumIndex, returns -1 if the element does not exist
lastIndexOf(obj)
withindexOf(obj)
Same thing, only ifobj
If it exists in the list, return the correspondingThe highestThe subscript, i.e.,The lastThe index that appears.
listIterator
:
subList
Return to the list for any non structural changes (i.e., change some data) will response to the original list, pair if make structural changes in the list (such as change the length), so will be reflected in the original list (i.e., the length of the original list will also change), if the original list of structural changes, if affect the child list (for exampleparentList.removeAll(childList)
), then the operation on the sublist is undefined (i.echildList.foreach(li->{System.out.println(li)})
Will be submitted to theConcurrentModificationException
).
spliterator
This method will be explained in more detail later in functional programming.