What is the Java ?: operator called and what does it do?

前端 未结 16 1704
轮回少年
轮回少年 2020-11-21 05:27

I have been working with Java a couple of years, but up until recently I haven\'t run across this construct:

int count = isHere ? getHereCount(index) : getAw         


        
16条回答
  •  臣服心动
    2020-11-21 06:25

    condition ? truth : false;
    

    If the condition is true then evaluate the first expression. If the condition is false, evaluate the second expression.

    It is called the Conditional Operator and it is a type of Ternary Operation.

提交回复
热议问题