?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Difficult

String Array and Char Array

APCSA-YVENNY

Consider the following declaration statements.

 char[] letters = {'d','o','g'};
String pet = "dog";

Which of the following segments of code will print "equal" to the console?
I.

if (pet.equals(letters))
    System.out.println("equal");
else
    System.out.println("not equal");

II.

if (pet.equals(new String(letters)))
    System.out.println("equal");
else
    System.out.println("not equal");

III.

if (pet==letters)
    System.out.println("equal");
else
    System.out.println("not equal");
A

I only.

B

II only.

C

III only.

D

I and II only.

E

I, II and III.