The following are just some important points:

  1. If the list length exceedsInteger.MAX_VALUEIf so, returnInteger.MAX_VALUE.
  2. If the list is not allowed to includenullElement, ifofornull, then throwNullPointerException.
  3. toArrayMethod returns an array without an internal reference to the list.
  4. toArrayIn:
  • If the runtime type of the array passed is notlistWhen 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 tonull.
  • If the specified array isnullIs 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, twotoArrayMethod, 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

  1. addIf the list is rejectednullElement is addednullElement is thrownNullPointerException.
  2. removeMethod removes the element with the lowest index.
  3. addAllMethod 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 existnullIf the elements:obj==null, you findnullElement index, returns -1 if it does not exist, returns -1 if it doesnullElement subscript.
  • If the list cannot existnullIf the elements:obj==null, then throwNullPointerException.
  • ifobj! =nullTo return toobjThe correspondingThe minimumIndex, returns -1 if the element does not exist
  1. lastIndexOf(obj)withindexOf(obj)Same thing, only ifobjIf it exists in the list, return the correspondingThe highestThe subscript, i.e.,The lastThe index that appears.
  2. listIterator:
  3. subListReturn 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).
  4. spliteratorThis method will be explained in more detail later in functional programming.