• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

和lt;和lt;= 运算符在 Java ?

用户头像
it1352
帮助1

问题说明

您能否解释一下来自 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;

正确答案

#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.

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tangicajk
系列文章
更多 icon
同类精品
更多 icon
继续加载