Multiple choice

The code snippet if( "Welcome".trim() == "Welcome".trim() ) System.out.println("Equal"); else System.out.println("Not Equal"); will

  1. compile and display “Equal”

  2. compile and display “Not Equal”

  3. cause a compiler error

  4. compile and display NULL

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The trim method removes leading and trailing whitespace, returning "Welcome". When compared using the equality operator ==, Java compares object references. Since string literals of the same value are interned and pooled together in Java, both references point to the exact same object in the string pool, evaluating to true and printing Equal.