What does "(o==null ? a==null : o.equals(a))" mean in Java? I'm reading this from the "contains" method documentation of an ArrayList.
Asked
Active
Viewed 40 times
1 Answers
1
It's ternary comparison, and is equivalent to the following if statement:
if (o == null)
a == null;
else
o.equals(a);

Leaderboard
- 371
- 1
- 10
-
2Yes and no. It's more like: "The value of `x` given `if (o == null) x = (a == null); else x = o.equals(a);`" – Federico klez Culloca Jul 09 '22 at 09:59
-
-
1@Leaderboard that is the point, just `(o==null ? a==null : o.equals(a))` does not mean / do anything, it is either accompanied by an `something = ...` or `return ...`. – luk2302 Jul 09 '22 at 10:01
-
@Leaderboard I mean that `(o==null ? a==null : o.equals(a))` actually evaluates to something. Your code doesn't. – Federico klez Culloca Jul 09 '22 at 10:01
-
1Indeed it doesn't; I was just converting the exact text the OP wrote. Aware in practice that's set to some variable (x in Federico's comment). – Leaderboard Jul 09 '22 at 10:02