Is there a way to implement this in a ternary operation. I’m very new to that ternary stuff, maybe you could guide me. This one doesn’t seem to work. Answer In this case, you don’t even need a ternary operator: Or, cleaner: Your version: is semantically incorrect: ternary operator should represent alternative assignments, it’s not a full replacement for if
Tag: ternary-operator
If without else ternary operator
So far from I have been searching through the net, the statement always have if and else condition such as a ? b : c. I would like to know whether the if ternary statement can be used without else. Assuming i have the following code, i wish to close the PreparedStatement if it is not null (I am using
What is the Java ?: operator called and what does it do?
I have been working with Java a couple of years, but up until recently I haven’t run across this construct: This is probably a very simple question, but can someone explain it? How do I read it? I am pretty sure I know how it works. if isHere is true, getHereCount() is called, if isHere is false getAwayCount() is called.