Boolean Expressions

AP Computer Science A· difficulty 2/5

public static boolean equalLists(int[] a, int[] b) {
    if (a == b) return true;
    return false;
}

What is wrong?

  • A

    == compares references; the contents must be checked element by element

    check_circle
  • B

    Arrays cannot be compared at all

  • C

    Nothing is wrong

  • D

    The method should return false first

Explanation

For arrays, == returns true only if both references point to the same object, not when contents are equal. The method must compare lengths and each element.

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

Related questions