String Objects: Concatenation, Literals, and More

AP Computer Science A· difficulty 3/5

String a = new String("hi");
String b = new String("hi");
System.out.println(a.equals(b));

What is printed?

  • A

    0

  • B

    false

  • C

    true

    check_circle
  • D

    Error

Explanation

The equals method compares the contents of the strings; both contain "hi", so it returns true.

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

Related questions