闆嗗悎ArrayList鍒嗘瀽
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了闆嗗悎ArrayList鍒嗘瀽相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/iter' title='iter'>iter capacity 鏈哄埗 rac math tor vat ali
鐩綍
ArrayList
鎻忚堪
- 缁ф壙AbstractList绫伙紝瀹炵幇List鎺ュ彛
- 瀹炵幇浜哛andmoAccess鎺ュ彛锛屽嵆鎻愪緵浜嗛殢鏈鸿闂姛鑳?/li>
- 瀹炵幇浜咰loneable鎺ュ彛锛屽嵆瑕嗙洊浜嗗嚱鏁癱lone()锛岃兘琚厠闅嗐€?/li>
- 瀹炵幇java.io.Serializable鎺ュ彛锛岃繖鎰忓懗鐫€ArrayList鏀寔搴忓垪鍖栵紝鑳介€氳繃搴忓垪鍖栧幓浼犺緭銆?/li>
- 鍩轰簬娉涘瀷鍔ㄦ€佹暟缁?List
)鎵╁(纰板埌鏁扮粍鍏堟兂鍒拌繛缁殑鍐呭瓨绌洪棿锛屾晠绌洪棿鏁堢巼涓嶉珮) ArrayList
鍙互浠(1)鐨勬椂闂村鏉傚害鍘绘牴鎹笅鏍囪闂厓绱犮€?鏃堕棿鏁堢巼寰堥珮)- 绾跨▼涓嶅畨鍏?/strong>鐨勶紝鍏佽鍏冪礌涓簄ull
閬嶅巻浣跨敤
浣跨敤for寰幆锛岄€氳繃绱㈠紩闅忔満璁块棶鏁堢巼鏈€楂橈紝鍏舵鏄痜oreach寰幆锛屾渶鎱㈡槸杩唬鍣ㄥ惊鐜?/p>
foreach 鏈€缁堜細琚浆鎹㈡垚杩唬鍣ㄩ亶鍘嗙殑褰㈠紡锛屾墍浠ユ槸涓嶅for寰幆鐨?/p>
涓嶤ollection鍏崇郴
public class ArrayList<E> extends AbstractList<E> implements List<E>, RandomAccess, Cloneable, Serializable
// 搴忓垪鍖杋d
private static final long serialVersionUID = 8683452581122892189L;
// 榛樿鍒濆鐨勫閲? private static final int DEFAULT_CAPACITY = 10;
// 涓€涓┖瀵硅薄
private static final Object[] EMPTY_ELEMENTDATA = new Object[0];
// 涓€涓┖瀵硅薄锛屽鏋滀娇鐢ㄩ粯璁ゆ瀯閫犲嚱鏁板垱寤猴紝鍒欓粯璁ゅ璞″唴瀹归粯璁ゆ槸璇ュ€? private static final Object[] DEFAULTCAPACITY_EMPTY_ELEMENTDATA = new Object[0];
// 褰撳墠鏁版嵁瀵硅薄瀛樻斁鍦版柟锛屽綋鍓嶅璞′笉鍙備笌搴忓垪鍖? transient Object[] elementData;
// 褰撳墠鏁扮粍闀垮害
private int size;
// 鏁扮粍鏈€澶ч暱搴? private static final int MAX_ARRAY_SIZE = 2147483639;
transient鍏抽敭瀛楄В鏋?/h3>
Java涓璽ransient鍏抽敭瀛楃殑浣滅敤锛岀畝鍗曞湴璇达紝灏辨槸璁╂煇浜涜淇グ鐨勬垚鍛樺睘鎬у彉閲忎笉琚簭鍒楀寲銆?/p>
Java涓璽ransient鍏抽敭瀛楃殑浣滅敤锛岀畝鍗曞湴璇达紝灏辨槸璁╂煇浜涜淇グ鐨勬垚鍛樺睘鎬у彉閲忎笉琚簭鍒楀寲銆?/p>
鏈変簡transient
鍏抽敭瀛楀0鏄庯紝鍒欒繖涓彉閲忎笉浼氬弬涓庡簭鍒楀寲鎿嶄綔锛屽嵆浣挎墍鍦ㄧ被瀹炵幇浜哠erializable鎺ュ彛锛屽弽搴忓垪鍖栧悗璇ュ彉閲忎负绌哄€笺€?/p>
閭d箞闂鏉ヤ簡锛欰rrayList涓暟缁勫0鏄庯細
transient Object[] elementData;
锛屼簨瀹炰笂鎴戜滑浣跨敤ArrayList鍦ㄧ綉缁滀紶杈撶敤鐨勫緢姝e父锛屽苟娌℃湁鍑虹幇绌哄€笺€?/p>
鍘熸潵锛?code>ArrayList鍦ㄥ簭鍒楀寲鐨勬椂鍊欎細璋冪敤writeObject()
鏂规硶锛屽皢size
鍜?code>element鍐欏叆ObjectOutputStream
锛涘弽搴忓垪鍖栨椂璋冪敤readObject()
锛屼粠ObjectInputStream
鑾峰彇size
鍜?code>element锛屽啀鎭㈠鍒?code>elementData銆?/p>
閭d负浠€涔堜笉鐩存帴鐢╡lementData鏉ュ簭鍒楀寲锛岃€岄噰鐢ㄤ笂璇夌殑鏂瑰紡鏉ュ疄鐜板簭鍒楀寲鍛紵
鍘熷洜鍦ㄤ簬elementData
鏄竴涓紦瀛樻暟缁勶紝瀹冮€氬父浼氶鐣欎竴浜涘閲忥紝绛夊閲忎笉瓒虫椂鍐嶆墿鍏呭閲忥紝閭d箞鏈変簺绌洪棿鍙兘灏辨病鏈夊疄闄呭瓨鍌ㄥ厓绱狅紝閲囩敤涓婅瘔鐨勬柟寮忔潵瀹炵幇搴忓垪鍖栨椂锛屽氨鍙互淇濊瘉鍙簭鍒楀寲瀹為檯瀛樺偍鐨勯偅浜涘厓绱狅紝鑰屼笉鏄暣涓暟缁勶紝浠庤€?strong>鑺傜渷绌洪棿鍜屾椂闂?/strong>銆?/p>
鎵€浠rrayList鐨勮璁¤€呭皢elementData璁捐涓簍ransient锛岀劧鍚庡湪writeObject鏂规硶涓墜鍔ㄥ皢鍏跺簭鍒楀寲锛屽苟涓斿彧搴忓垪鍖栦簡瀹為檯瀛樺偍鐨勯偅浜涘厓绱狅紝鑰屼笉鏄暣涓暟缁勩€?/p>
瑙佹簮鐮侊細
// Write out all elements in the proper order.for (int i=0; i<size; i++) s.writeObject(elementData[i]);
浠庢簮鐮佷腑锛屽彲浠ヨ瀵熷埌 寰幆鏃舵槸浣跨敤i<size鑰屼笉鏄?i<elementData.length锛岃鏄庡簭鍒楀寲鏃讹紝鍙渶瀹為檯瀛樺偍鐨勯偅浜涘厓绱狅紝鑰屼笉鏄暣涓暟缁勩€?/p>
鏃犲弬鏋勯€?/h3>
public ArrayList()
this.elementData = DEFAULTCAPACITY_EMPTY_ELEMENTDATA;
public ArrayList()
this.elementData = DEFAULTCAPACITY_EMPTY_ELEMENTDATA;
榛樿鏃犲弬鏋勫缓鏂规硶鍒涘缓ArrayList瀵硅薄
new ArrayList() 鍒涘缓瀵硅薄锛屾暟缁勯暱搴ize=0锛岃€宔lementData鏁扮粍鐨勯暱搴︿负size+1锛?/p>
绗竴娆dd鏃讹紝elementData浼氬彉鎴愰粯璁ら暱搴?10(DEFAULT_CAPACITY)
public ArrayList(int initialCapacity)
if (initialCapacity > 0)
this.elementData = new Object[initialCapacity];
else if (initialCapacity == 0)
this.elementData = EMPTY_ELEMENTDATA;
else
throw new IllegalArgumentException("Illegal Capacity: "+
initialCapacity);
initialCapacity鎸囧畾鍒濆鏁扮粍闀垮害銆?/p>
public ArrayList(Collection<? extends E> c)
elementData = c.toArray();
if ((size = elementData.length) != 0)
// c.toArray might (incorrectly) not return Object[] (see 6260652)
if (elementData.getClass() != Object[].class)
elementData = Arrays.copyOf(elementData, size, Object[].class);
else
// replace with empty array.
this.elementData = EMPTY_ELEMENTDATA;
- 灏哻ollection瀵硅薄杞崲鎴愭暟缁勶紝鐒跺悗灏嗘暟缁勭殑鍦板潃璧嬬粰elementData銆?/li>
- 鏇存柊size鐨勫€硷紝鍚屾椂鍒ゆ柇size鐨勫ぇ灏忥紝濡傛灉鏄痵ize绛変簬0锛岀洿鎺ュ皢绌哄璞MPTY_ELEMENTDATA鐨勫湴鍧€璧嬬粰elementData
- 濡傛灉size鐨勫€煎ぇ浜?锛屽垯鎵цArrays.copyOf鏂规硶锛屾妸collection瀵硅薄鐨勫唴瀹癸紙鍙互鐞嗚В涓烘繁鎷疯礉锛塩opy鍒癳lementData涓€?/li>
娉ㄦ剰锛歵his.elementData = arg0.toArray(); 杩欓噷鎵ц鐨勭畝鍗曡祴鍊兼槸娴呮嫹璐濓紝鎵€浠ヨ鎵цArrays.copyOf鍋氭繁鎷疯礉
add(E e)鏂规硶
/**
*澧炲姞鎸囧畾鐨勫厓绱犲埌ArrayList鐨勬渶鍚庝綅缃? * @param e 瑕佹坊鍔犵殑鍏冪礌
* @return
*/
public boolean add(E e)
// 纭畾ArrayList鐨勫閲忓ぇ灏?--涓ヨ皑
// 娉ㄦ剰锛歴ize + 1锛屼繚璇佽祫婧愮┖闂翠笉琚氮璐癸紝
// 鈽嗏槅鈽嗘寜褰撳墠鎯呭喌锛屼繚璇佽瀛樺灏戜釜鍏冪礌锛屽氨鍙垎閰嶅灏戠┖闂磋祫婧? ensureCapacityInternal(size + 1); // Increments modCount!!
elementData[size++] = e;
return true;
/**
* 绉佹湁鏂规硶锛氭槑纭?ArrayList 鐨勫閲忥紝鎻愪緵缁欐湰绫讳娇鐢ㄧ殑鏂规硶
* - 鐢ㄤ簬鍐呴儴浼樺寲锛屼繚璇佺┖闂磋祫婧愪笉琚氮璐癸細灏ゅ叾鍦?add() 鏂规硶娣诲姞鏃惰捣鏁? * @param minCapacity 鎸囧畾鐨勬渶灏忓閲? */
private void ensureCapacityInternal(int minCapacity)
// 鑻?elementData == 锛屽垯鍙?minCapacity 涓?榛樿瀹归噺鍜屽弬鏁?minCapacity 涔嬮棿鐨勬渶澶у€? // 娉細ensureCapacity() 鏄彁渚涚粰鐢ㄦ埛浣跨敤鐨勬柟娉曪紝鍦?ArrayList 鐨勫疄鐜颁腑骞舵病鏈変娇鐢? if (elementData == DEFAULTCAPACITY_EMPTY_ELEMENTDATA)
minCapacity= Math.max(DEFAULT_CAPACITY, minCapacity);
ensureExplicitCapacity(minCapacity);
/**
* 绉佹湁鏂规硶锛氭槑纭?ArrayList 鐨勫閲? * - 鐢ㄤ簬鍐呴儴浼樺寲锛屼繚璇佺┖闂磋祫婧愪笉琚氮璐癸細灏ゅ叾鍦?add() 鏂规硶娣诲姞鏃惰捣鏁? * @param minCapacity 鎸囧畾鐨勬渶灏忓閲? */
private void ensureExplicitCapacity(int minCapacity)
// 灏嗏€滀慨鏀圭粺璁℃暟鈥?1锛岃鍙橀噺涓昏鏄敤鏉ュ疄鐜癴ail-fast鏈哄埗鐨? modCount++;
// 闃叉婧㈠嚭浠g爜锛氱‘淇濇寚瀹氱殑鏈€灏忓閲?> 鏁扮粍缂撳啿鍖哄綋鍓嶇殑闀垮害
// overflow-conscious code
if (minCapacity - elementData.length > 0)
grow(minCapacity);
/**
* 鏁扮粍缂撳啿鍖烘渶澶у瓨鍌ㄥ閲? * - 涓€浜?VM 浼氬湪涓€涓暟缁勪腑瀛樺偍鏌愪簺鏁版嵁--->涓轰粈涔堣鍑忓幓 8 鐨勫師鍥? * - 灏濊瘯鍒嗛厤杩欎釜鏈€澶у瓨鍌ㄥ閲忥紝鍙兘浼氬鑷?OutOfMemoryError(褰撹鍊?> VM 鐨勯檺鍒舵椂)
*/
private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
/**
* 绉佹湁鏂规硶锛氭墿瀹癸紝浠ョ‘淇?ArrayList 鑷冲皯鑳藉瓨鍌?minCapacity 涓厓绱? * - 鎵╁璁$畻锛歯ewCapacity = oldCapacity + (oldCapacity >> 1); 鎵╁厖褰撳墠瀹归噺鐨?.5鍊? * @param minCapacity 鎸囧畾鐨勬渶灏忓閲? */
private void grow(int minCapacity)
// 闃叉婧㈠嚭浠g爜
int oldCapacity = elementData.length;// 鏃у閲忓ぇ灏? int newCapacity = oldCapacity + (oldCapacity >> 1); // 鏂板閲忎负鏃у閲忕殑1.5鍊? if (newCapacity - minCapacity < 0) // 鑻?newCapacity鏂板閲忓皬浜庡弬鏁版寚瀹氬閲忥紝淇敼鏂板閲? newCapacity = minCapacity;
if (newCapacity - MAX_ARRAY_SIZE > 0) // 鑻?newCapacity 澶т簬鏈€澶у瓨鍌ㄥ閲忥紝鍒欒繘琛屽ぇ瀹归噺鍒嗛厤
newCapacity = hugeCapacity(minCapacity);
// 鎷疯礉鎵╁
elementData = Arrays.copyOf(elementData, newCapacity);
/**
* 绉佹湁闈欐€佹柟娉曪細澶у閲忓垎閰嶏紝鏈€澶у垎閰?Integer.MAX_VALUE
* @param minCapacity
*/
private static int hugeCapacity(int minCapacity)
if (minCapacity < 0) // overflow
throw new OutOfMemoryError();
return (minCapacity > MAX_ARRAY_SIZE) ?
Integer.MAX_VALUE :
MAX_ARRAY_SIZE;
/**
*澧炲姞鎸囧畾鐨勫厓绱犲埌ArrayList鐨勬渶鍚庝綅缃? * @param e 瑕佹坊鍔犵殑鍏冪礌
* @return
*/
public boolean add(E e)
// 纭畾ArrayList鐨勫閲忓ぇ灏?--涓ヨ皑
// 娉ㄦ剰锛歴ize + 1锛屼繚璇佽祫婧愮┖闂翠笉琚氮璐癸紝
// 鈽嗏槅鈽嗘寜褰撳墠鎯呭喌锛屼繚璇佽瀛樺灏戜釜鍏冪礌锛屽氨鍙垎閰嶅灏戠┖闂磋祫婧? ensureCapacityInternal(size + 1); // Increments modCount!!
elementData[size++] = e;
return true;
/**
* 绉佹湁鏂规硶锛氭槑纭?ArrayList 鐨勫閲忥紝鎻愪緵缁欐湰绫讳娇鐢ㄧ殑鏂规硶
* - 鐢ㄤ簬鍐呴儴浼樺寲锛屼繚璇佺┖闂磋祫婧愪笉琚氮璐癸細灏ゅ叾鍦?add() 鏂规硶娣诲姞鏃惰捣鏁? * @param minCapacity 鎸囧畾鐨勬渶灏忓閲? */
private void ensureCapacityInternal(int minCapacity)
// 鑻?elementData == 锛屽垯鍙?minCapacity 涓?榛樿瀹归噺鍜屽弬鏁?minCapacity 涔嬮棿鐨勬渶澶у€? // 娉細ensureCapacity() 鏄彁渚涚粰鐢ㄦ埛浣跨敤鐨勬柟娉曪紝鍦?ArrayList 鐨勫疄鐜颁腑骞舵病鏈変娇鐢? if (elementData == DEFAULTCAPACITY_EMPTY_ELEMENTDATA)
minCapacity= Math.max(DEFAULT_CAPACITY, minCapacity);
ensureExplicitCapacity(minCapacity);
/**
* 绉佹湁鏂规硶锛氭槑纭?ArrayList 鐨勫閲? * - 鐢ㄤ簬鍐呴儴浼樺寲锛屼繚璇佺┖闂磋祫婧愪笉琚氮璐癸細灏ゅ叾鍦?add() 鏂规硶娣诲姞鏃惰捣鏁? * @param minCapacity 鎸囧畾鐨勬渶灏忓閲? */
private void ensureExplicitCapacity(int minCapacity)
// 灏嗏€滀慨鏀圭粺璁℃暟鈥?1锛岃鍙橀噺涓昏鏄敤鏉ュ疄鐜癴ail-fast鏈哄埗鐨? modCount++;
// 闃叉婧㈠嚭浠g爜锛氱‘淇濇寚瀹氱殑鏈€灏忓閲?> 鏁扮粍缂撳啿鍖哄綋鍓嶇殑闀垮害
// overflow-conscious code
if (minCapacity - elementData.length > 0)
grow(minCapacity);
/**
* 鏁扮粍缂撳啿鍖烘渶澶у瓨鍌ㄥ閲? * - 涓€浜?VM 浼氬湪涓€涓暟缁勪腑瀛樺偍鏌愪簺鏁版嵁--->涓轰粈涔堣鍑忓幓 8 鐨勫師鍥? * - 灏濊瘯鍒嗛厤杩欎釜鏈€澶у瓨鍌ㄥ閲忥紝鍙兘浼氬鑷?OutOfMemoryError(褰撹鍊?> VM 鐨勯檺鍒舵椂)
*/
private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
/**
* 绉佹湁鏂规硶锛氭墿瀹癸紝浠ョ‘淇?ArrayList 鑷冲皯鑳藉瓨鍌?minCapacity 涓厓绱? * - 鎵╁璁$畻锛歯ewCapacity = oldCapacity + (oldCapacity >> 1); 鎵╁厖褰撳墠瀹归噺鐨?.5鍊? * @param minCapacity 鎸囧畾鐨勬渶灏忓閲? */
private void grow(int minCapacity)
// 闃叉婧㈠嚭浠g爜
int oldCapacity = elementData.length;// 鏃у閲忓ぇ灏? int newCapacity = oldCapacity + (oldCapacity >> 1); // 鏂板閲忎负鏃у閲忕殑1.5鍊? if (newCapacity - minCapacity < 0) // 鑻?newCapacity鏂板閲忓皬浜庡弬鏁版寚瀹氬閲忥紝淇敼鏂板閲? newCapacity = minCapacity;
if (newCapacity - MAX_ARRAY_SIZE > 0) // 鑻?newCapacity 澶т簬鏈€澶у瓨鍌ㄥ閲忥紝鍒欒繘琛屽ぇ瀹归噺鍒嗛厤
newCapacity = hugeCapacity(minCapacity);
// 鎷疯礉鎵╁
elementData = Arrays.copyOf(elementData, newCapacity);
/**
* 绉佹湁闈欐€佹柟娉曪細澶у閲忓垎閰嶏紝鏈€澶у垎閰?Integer.MAX_VALUE
* @param minCapacity
*/
private static int hugeCapacity(int minCapacity)
if (minCapacity < 0) // overflow
throw new OutOfMemoryError();
return (minCapacity > MAX_ARRAY_SIZE) ?
Integer.MAX_VALUE :
MAX_ARRAY_SIZE;
1锛夌‘淇濇暟缁勫凡浣跨敤闀垮害锛坰ize锛夊姞1涔嬪悗瓒冲瀛樹笅 涓嬩竴涓暟鎹?br /> 2锛変慨鏀规鏁癿odCount 鏍囪瘑鑷1锛屽鏋滃綋鍓嶆暟缁勫凡浣跨敤闀垮害锛坰ize锛夊姞1鍚庣殑澶т簬褰撳墠鐨勬暟缁勯暱搴︼紝鍒欒皟鐢╣row鏂规硶锛屽闀挎暟缁勶紝grow鏂规硶浼氬皢褰撳墠鏁扮粍鐨勯暱搴﹀彉涓哄師鏉ュ閲忕殑1.5鍊嶃€?br /> 3锛夌‘淇濇柊澧炵殑鏁版嵁鏈夊湴鏂瑰瓨鍌ㄤ箣鍚庯紝鍒欏皢鏂板厓绱犳坊鍔犲埌浣嶄簬size鐨勪綅缃笂銆?br /> 4锛夎繑鍥炴坊鍔犳垚鍔熷竷灏斿€笺€?/p>
remove()鏂规硶
鍒犻櫎鎸囧畾浣嶇疆鐨勫厓绱犮€?/p>
//鍒犻櫎鎸囧畾浣嶇疆鐨勫厓绱狅紝杩斿洖琚垹闄ょ殑鍏冪礌
public E remove(int index)
rangeCheck(index);
modCount++; //琚垹闄ゆ椂 modCount涔熶細鏀瑰彉
E oldValue = elementData(index);
int numMoved = size - index - 1;
if (numMoved > 0)
// 灏?index + 1 鍙婁箣鍚庣殑鍏冪礌鍚戝墠绉诲姩涓€浣嶏紝瑕嗙洊琚垹闄ゅ€? System.arraycopy(elementData, index+1, elementData, index,
numMoved);
//灏嗘渶鍚庝竴涓厓绱犵疆绌猴紝骞跺皢 size 鍊煎噺1
elementData[--size] = null; // clear to let GC do its work
return oldValue;
鐩存帴鍒犻櫎闆嗗悎涓煇涓厓绱狅紝濡傛灉鍏冪礌閲嶅锛屽垯鍙垹闄や笅鏍囨渶灏忕殑鍏冪礌
public boolean remove(Object o)
if (o == null)
for (int index = 0; index < size; index++)
if (elementData[index] == null)
fastRemove(index);
return true;
else
// 閬嶅巻鏁扮粍锛屾煡鎵捐鍒犻櫎鍏冪礌鐨勪綅缃? for (int index = 0; index < size; index++)
if (o.equals(elementData[index]))
fastRemove(index);
return true;
return false;
蹇€熷垹闄ゆ柟娉?/p>
娌℃湁鍋氳竟鐣屾鏌ワ紝鐩存帴杩涜鍒犻櫎鎿嶄綔
private void fastRemove(int index)
modCount++;
int numMoved = size - index - 1;
if (numMoved > 0)
System.arraycopy(elementData, index+1, elementData, index,
numMoved);
elementData[--size] = null; // clear to let GC do its work
鍒犻櫎鎿嶄綔鐨勬楠わ細
- 鑾峰彇鎸囧畾浣嶇疆 index 澶勭殑鍏冪礌鍊?/li>
- 灏?index + 1 鍙婁箣鍚庣殑鍏冪礌鍚戝墠绉诲姩涓€浣?/li>
- 灏嗘渶鍚庝竴涓厓绱犵疆绌猴紝骞跺皢 size 鍊煎噺 1
- 杩斿洖琚垹闄ゅ€硷紝瀹屾垚鍒犻櫎鎿嶄綔
html " >
Java闆嗗悎妗嗘灦銆?/p>
婧愮爜娉ㄩ噴鎬荤粨锛?/p>
鍦ㄩ亣鍒板苟鍙戜慨鏀规椂锛岃凯浠e櫒浼?strong>灏芥渶澶у姫鍔?/strong>鎶涘嚭ConcurrentModificationException杩欎釜寮傚父锛?/p>
浣嗕笉鑳界櫨鍒嗕箣鐧剧殑淇濊瘉锛岃€岃凯浠e櫒鐨勫揩閫熷け璐ワ紝浼氶伩鍏嶇▼搴忓湪灏嗘潵涓嶇‘瀹氱殑鏃堕棿閲屽嚭鐜颁笉纭畾鐨勮涓恒€?/p>
涓轰粈涔圓rrayList缁ф壙浜咥bstractList杩樿瀹炵幇List鎺ュ彛 锛?/h3>
闃叉鍦ㄤ唬鐞嗘椂鍑洪敊
鍏跺疄娌℃湁蹇呰锛屽疄鐜颁笌涓嶅疄鐜伴兘鏄彲浠ョ殑銆?/p>
System.arraycopy()鍜孉rrays.copyof()
- Arrays.copyOf()鍐呴儴杩樿皟鐢ㄤ簡System.arraycopy()杩欎釜鏂规硶
- System.arraycopy()闇€瑕佷紶涓€涓暟缁勭殑鍙傛暟杩涜鎷疯礉銆?/li>
- 鑰孉rrays.copyof()鑷繁鍐呴儴浼氬垱寤轰竴涓柊鐨勬暟缁勮繘琛屾嫹璐?/li>
以上是关于闆嗗悎ArrayList鍒嗘瀽的主要内容,如果未能解决你的问题,请参考以下文章