最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

ArrayList及HashMap的擴(kuò)容規(guī)則講解

 更新時(shí)間:2019年02月12日 16:23:39   作者:wlmmmm  
今天小編就為大家分享一篇關(guān)于ArrayList及HashMap的擴(kuò)容規(guī)則講解,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧

1、ArrayList

默認(rèn)大小為10

/**
 * Default initial capacity.
*/
private static final int DEFAULT_CAPACITY = 10;

最大容量為2^30 - 8

 /**
 * The maximum size of array to allocate.
 * Some VMs reserve some header words in an array.
 * Attempts to allocate larger arrays may result in
 * OutOfMemoryError: Requested array size exceeds VM limit
 */
private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
/**
 * A constant holding the maximum value an {@code int} can
 * have, 2<sup>31</sup>-1.
*/
public static final int  MAX_VALUE = 0x7fffffff;

擴(kuò)容規(guī)則為:oldCapacity*1.5

/**
 * Increases the capacity to ensure that it can hold at least the
 * number of elements specified by the minimum capacity argument.
 * @param minCapacity the desired minimum capacity
 */
private void grow(int minCapacity) {
  // overflow-conscious code
  int oldCapacity = elementData.length;
  int newCapacity = oldCapacity + (oldCapacity >> 1);
  if (newCapacity - minCapacity < 0)
    newCapacity = minCapacity;
  if (newCapacity - MAX_ARRAY_SIZE > 0)
    newCapacity = hugeCapacity(minCapacity);
  // minCapacity is usually close to size, so this is a win:
  elementData = Arrays.copyOf(elementData, newCapacity);
}

2、HashMap

默認(rèn)大?。?16

/**
 * The default initial capacity - MUST be a power of two.
*/
static final int DEFAULT_INITIAL_CAPACITY = 1 << 4; // aka 16

最大容量為:2^30

/**
 * The maximum capacity, used if a higher value is implicitly specified
 * by either of the constructors with arguments.
 * MUST be a power of two <= 1<<30.
*/
static final int MAXIMUM_CAPACITY = 1 << 30;

擴(kuò)容規(guī)則為:大于oldCapacity的最小的2的n次方整數(shù)

/**
 * Adds a new entry with the specified key, value and hash code to
 * the specified bucket. It is the responsibility of this
 * method to resize the table if appropriate.
 * Subclass overrides this to alter the behavior of put method.
 */
void addEntry(int hash, K key, V value, int bucketIndex) {
  if ((size >= threshold) && (null != table[bucketIndex])) {
    resize(2 * table.length);
    hash = (null != key) ? hash(key) : 0;
    bucketIndex = indexFor(hash, table.length);
  }
  createEntry(hash, key, value, bucketIndex);
}

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請(qǐng)查看下面相關(guān)鏈接

相關(guān)文章

  • JVM的基本介紹以及垃圾回收

    JVM的基本介紹以及垃圾回收

    垃圾回收(Garbage Collection,GC),顧名思義就是釋放垃圾占用的空間,防止內(nèi)存泄露,這篇文章主要給大家介紹了關(guān)于JVM垃圾回收的相關(guān)資料,需要的朋友可以參考下
    2021-09-09
  • java實(shí)現(xiàn)單機(jī)版五子棋小游戲

    java實(shí)現(xiàn)單機(jī)版五子棋小游戲

    這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)單機(jī)版五子棋小游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-12-12
  • Java判斷多個(gè)時(shí)間段是否重合的方法小結(jié)

    Java判斷多個(gè)時(shí)間段是否重合的方法小結(jié)

    這篇文章主要為大家詳細(xì)介紹了Java中判斷多個(gè)時(shí)間段是否重合的方法,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2025-02-02
  • Sharding-Proxy分庫分表和數(shù)據(jù)加密使用場(chǎng)景分析

    Sharding-Proxy分庫分表和數(shù)據(jù)加密使用場(chǎng)景分析

    這篇文章主要介紹了Sharding-Proxy分庫分表和數(shù)據(jù)加密使用經(jīng)驗(yàn)分享,通過場(chǎng)景模擬分析結(jié)合示例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2022-04-04
  • 詳解Spring中singleton?bean如何同時(shí)服務(wù)多個(gè)請(qǐng)求

    詳解Spring中singleton?bean如何同時(shí)服務(wù)多個(gè)請(qǐng)求

    這篇文章主要介紹了詳解Spring中singleton?bean如何同時(shí)服務(wù)多個(gè)請(qǐng)求
    2023-02-02
  • eclipse springboot工程打war包方法及再Tomcat中運(yùn)行的方法

    eclipse springboot工程打war包方法及再Tomcat中運(yùn)行的方法

    這篇文章主要介紹了eclipse springboot工程打war包方法及再Tomcat中運(yùn)行的方法,本文圖文并茂給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-08-08
  • Java中的TreeSet源碼解讀

    Java中的TreeSet源碼解讀

    這篇文章主要介紹了Java中的TreeSet源碼解讀,TreeSet 是一個(gè) 有序集合,它擴(kuò)展了 AbstractSet 類并實(shí)現(xiàn)了 NavigableSet 接口,對(duì)象根據(jù)其自然順序以升序排序和存儲(chǔ),該 TreeSet 中使用 平衡樹,更具體的一個(gè) 紅黑樹,需要的朋友可以參考下
    2023-09-09
  • PowerJob的ServerDiscoveryService工作流程源碼解讀

    PowerJob的ServerDiscoveryService工作流程源碼解讀

    這篇文章主要為大家介紹了PowerJob的ServerDiscoveryService工作流程源碼解讀,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-12-12
  • Java基礎(chǔ)之TreeMap詳解

    Java基礎(chǔ)之TreeMap詳解

    這篇文章主要介紹了Java基礎(chǔ)之TreeMap詳解,文中有非常詳細(xì)的代碼示例,對(duì)正在學(xué)習(xí)java基礎(chǔ)的小伙伴們有非常好的幫助,需要的朋友可以參考下
    2021-04-04
  • 詳解IntelliJ IDEA 自定義方法注解模板

    詳解IntelliJ IDEA 自定義方法注解模板

    本篇文章主要介紹了IntelliJ IDEA 自定義方法注解模板,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-12-12

最新評(píng)論

竹山县| 芦溪县| 鹤峰县| 白沙| 万州区| 老河口市| 富顺县| 江阴市| 大石桥市| 马鞍山市| 桃园市| 连南| 南昌市| 涿鹿县| 武宁县| 福海县| 确山县| 驻马店市| 黄冈市| 胶州市| 临沭县| 藁城市| 洪雅县| 淳安县| 山丹县| 西藏| 乌拉特中旗| 英吉沙县| 蛟河市| 缙云县| 苗栗县| 襄城县| 昂仁县| 梅河口市| 霍林郭勒市| 抚州市| 侯马市| 铁力市| 天峨县| 新昌县| 泸水县|