When should null values of Boolean be used?

前端 未结 14 2372
心在旅途
心在旅途 2020-12-04 07:32

Java boolean allows values of true and false while Boolean allows true, false, and null. I have

14条回答
  •  眼角桃花
    2020-12-04 07:53

    Boolean wrapper is useful when you want to whether value was assigned or not apart from true and false. It has the following three states:

    • True
    • False
    • Not defined which is null

    Whereas boolean has only two states:

    • True
    • False

    The above difference will make it helpful in Lists of Boolean values, which can have True, False or Null.

提交回复
热议问题