Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java boolean return if statement [duplicate]

Can someone please explain, in simple English, the logic behind this statement?

return mContainsLoadingRow ? (getContentDataSize() + 1) : getContentDataSize();

Assuming mContainsLoadingRow is a boolean, if mContainsLoadingRow is true,

then return getContentDataSize() + 1.

If not, return getContentDataSize().

Is that the correct way to look at this?

like image 957
Martin Erlic Avatar asked Jul 15 '26 07:07

Martin Erlic


1 Answers

this complete expression is know as Ternary Operator in Java.

Code Statement

mContainsLoadingRow ? (getContentDataSize() + 1) : getContentDataSize();
        ||                       ||                         ||
 //boolean expression      //return if true          //return if false

here in this code

mContainsLoadingRow is a Boolean variable which contains either true or false. you can also change mContainsLoadingRow with any Boolean expression like (a>b or b==a or b <= a etc.)

? (question mark) :- enables us to fine whether it is true or false.

if true the expression (getContentDataSize() + 1) will be return.

if false then expressin getContentDataSize() value will be return.

like image 60
Vikrant Kashyap Avatar answered Jul 19 '26 19:07

Vikrant Kashyap



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!