Checking the “boolean” result of an “int” type

前端 未结 8 1519
死守一世寂寞
死守一世寂寞 2020-12-10 23:43

I\'m learning Java, coming from C and I found an interesting difference between languages with the boolean type. In C there is no bool/ean

相关标签:
8条回答
  • 2020-12-11 00:34

    You could try something like that. Boolean i = true; if (i) System.out.println("i is true");

    Just initialize it as a boolean value rather than an integer.

    0 讨论(0)
  • 2020-12-11 00:37

    Try BooleanUtils from Apache common-lang.

      BooleanUtils.toBoolean(0) = Boolean.FALSE
      BooleanUtils.toBoolean(1) = Boolean.TRUE
      BooleanUtils.toBoolean(2) = Boolean.TRUE
    
    0 讨论(0)
提交回复
热议问题