What does this boolean “(number & 1) == 0” mean?

前端 未结 9 914
眼角桃花
眼角桃花 2020-12-08 01:27

On CodeReview I posted a working piece of code and asked for tips to improve it. One I got was to use a boolean method to check if an ArrayList had an even number of indices

9条回答
  •  天命终不由人
    2020-12-08 02:09

    It is performing a binary and against 1, which returns 0 if the least significant bit is not set

    for your example

    00001010 (10)

    00000001 (1)

    ===========

    00000000 (0)

提交回复
热议问题