本文介紹了<<= 運算符在 Java 中是什么意思?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
您能否解釋一下來自 HashMap 構造函數 特別是這一行
Can you please explain this code snippet from HashMap constructor specifically the line
容量<<= 1:
capacity <<= 1:
// Find a power of 2 >= initialCapacity
198 int capacity = 1;
199 while (capacity < initialCapacity)
200 capacity <<= 1;
推薦答案
相當于capacity = capacity <<<1;
.
該操作將容量的位向左移動一位,相當于乘以 2.
It is equivalent to capacity = capacity << 1;
.
That operation shifts capacity's bits one position to the left, which is equivalent to multiplying by 2.
您發布的特定代碼找到大于 initialCapacity
的 2 的最小冪.
The specific code you posted finds the smallest power of 2 which is larger than initialCapacity
.
所以如果 initialCapacity
為 27,例如 capacity
在循環后將是 32 (2^5).
So if initialCapacity
is 27, for example, capacity
will be 32 (2^5) after the loop.
這篇關于<<= 運算符在 Java 中是什么意思?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!