<Java>ArrayList中的add和set有什么区别
public void add(int index, E element) {
if (index > size || index < 0)
throw new IndexOutOfBoundsException("Index: "+index+", Size: "+size);
ensureCapacity(size+1); // Increments modCount!!
System.arraycopy(elementData, index, elementData, index + 1,size - index);
elementData[index] = element;
size++;
}
----------------------------------------------------
public E set(int index, E element) {
RangeCheck(index);
E oldValue = (E) elementData[index];
elementData[index] = element;
return oldValue;
}
是不是说add是塞进去一个
而set是覆盖?
攀登者IT技术交流总群:141098671(500人) || 攀登者IT【.Net】精英:172663374 || 攀登者IT【Java】精英:216931633欢迎你的加入进行技术探
讨!加群时请写好技术方向,否则不批准!