Given the code fragment:
What is the result?
A.
Match 1
B.
Match 2
C.
No Match
D.
A NullPointerException is thrown at runtime.
Given the code fragment:
What is the result?
A.
Match 1
B.
Match 2
C.
No Match
D.
A NullPointerException is thrown at runtime.
Answer is B. StringBuilder int constructor takes an int and creates empty obj with the int as a capacity. Call its toString and it will return an empty string. So
sb.toString().equals(s) will return true.
“”.equals(“”) in other words