Given the code fragment:
What is the result?
Given the code fragment:
What is the result?
The code first converts the StringBuilder object 'sb' to a String using the toString() method and then compares it with the String 's' using the equals() method. Since both 'sb.toString()' and 's' have the value 'Java', the equals() method returns true, and 'Match 1' is printed.
sb.toString() => converts it into String. and thereafter, using equals() method on String will do the value comparison. So, answer is A since the values are equal.
Answer A
Answer is A. As sb.toString() => new string object gets created and String equals() method do content check
Answer- A
The answer is A
Inconvertible type error between String "Java" and StringBuilder "Java". To resolve StringBuilder to String append .toString() method to sb
It is very simple since equals method compare by value.
A tostring convert a StringBuffer to a string