簡體   English   中英

Java中的HashMap和HashSet size()

[英]HashMap & HashSet size() in Java

我試圖找到有關此信息,但失敗了。

HashMapHashSet size()如何實現? 它是如何工作的? 它是O(1)還是O(n)運算?

這需要O(1)時間。 HashMap有一個size實例變量,在添加或刪除條目時會對其進行修改:

這是HashMap實現:

/**
 * Returns the number of key-value mappings in this map.
 *
 * @return the number of key-value mappings in this map
 */
public int size() {
    return size;
}

HashSet調用后備HashMap size()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM