intindexOfRange(Object o, int start, int end){ Object[] es = elementData; if (o == null) { for (int i = start; i < end; i++) { if (es[i] == null) { return i; } } } else { for (int i = start; i < end; i++) { if (o.equals(es[i])) { return i; } } } return -1; }
6.扩容
JDK11去掉了
add方法
1 2 3 4 5 6 7 8 9 10 11
/** * Appends the specified element to the end of this list. * * @param e element to be appended to this list * @return {@code true} (as specified by {@link Collection#add}) */ publicbooleanadd(E e){ modCount++; add(e, elementData, size); returntrue; }
1 2 3 4 5 6 7 8 9 10 11
/** * This helper method split out from add(E) to keep method * bytecode size under 35 (the -XX:MaxInlineSize default value), * which helps when add(E) is called in a C1-compiled loop. */ privatevoidadd(E e, Object[] elementData, int s){ if (s == elementData.length) elementData = grow(); elementData[s] = e; size = s + 1; }