I want this code to print true. I saw this question when passing my OCA7 exam. I know the thing about the string pool and all and I also know the difference between equals() and ==.
The exam question didn't offer the .equals() option. It only said to figure out a way to make this code to return true by comparing a Stringbuilder with a String "==" operator. I had to figure out 1 option among 4 other that all had used the "==". No equals –
package test.test;
public class SomeClass{
public static void main(String[] args) {
StringBuilder sb = new StringBuilder("abcd");
String str = sb.toString();
System.out.println(sb.toString() == str);
}
}