Converting Boolean to Integer in Java without If-Statements

后端 未结 12 1957
盖世英雄少女心
盖世英雄少女心 2020-12-30 02:26

I\'m wondering if there\'s a way to convert a boolean to an int without using if statements (as not to break the pipeline). For example, I could write

int bo         


        
12条回答
  •  半阙折子戏
    2020-12-30 03:03

    I found a solution by framework. Use compare for Boolean.

    // b = Your boolean result
    // v will be 1 if b equals true, otherwise 0
    int v = Boolean.compare(b, false);
    

提交回复
热议问题