Objects: Instances of Classes

AP Computer Science A· difficulty 4/5

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>

  • D

    if (s != null && s.length() > 0)

    check_circle

Explanation

Order matters: null-check first.

Want 10 more like this — adaptive to your weak spots?

Related questions