There are two types of if
statements in java - classic: if {} else {}
and shorthand: exp ? value1 : value2
. Is one faster than the oth
Both of your examples will probably compile to identical or nearly identical bytecode, so there should be no difference in performance.
Had there been a difference in execution speed, you should still use the most idiomatic version (which would be the second one for assigning a single variable based on a simple condition and two simple sub-expressions, and the first one for doing more complex operations or operations that do not fit on a single line).