Boolean Expressions

AP Computer Science A· difficulty 3/5

Best way to check if <code>s</code> is null or empty

  • A

    s == null || s.length() == 0

    check_circle
  • B

    s == ""

  • C

    s.equals(null) || s.equals("")

  • D

    s.length() == 0 (NPE if null)

Explanation

Short-circuit: check null first; works regardless of state.

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

Related questions