To safely call <code>s.length()</code> only if s is not null
- A
if (s.length() > 0 && s != null)
- B
Both work
- C
Use Optional<String>
- Dcheck_circle
if (s != null && s.length() > 0)
Explanation
Order matters: null-check first.
AP Computer Science A· difficulty 4/5
To safely call <code>s.length()</code> only if s is not null
if (s.length() > 0 && s != null)
Both work
Use Optional<String>
if (s != null && s.length() > 0)
Explanation
Order matters: null-check first.
Want 10 more like this — adaptive to your weak spots?