Stringbuilder s1= new StringBuilder("meow");
Stringbuilder s2 = new StringBuilder("meow");
if(s1 ==s2)System.out.println("one");
if(s1.equals(s2))System.out.println("two");
if(s1== "meow")System.out.println("three");
if(s1.toString() == "meow")System.out.println("four");
The answers are
Do not compile
Statement that do not compile is removed it prints "two"...
How it can print two when equals does not compile in stringbuilder....
StringBuilder
Moderator: admin
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: StringBuilder
Which line doesn't compile? All classes inherit equals method from Object class so why do you think s1.equals(s2) should not compile and should not return true?
Who is online
Users browsing this forum: No registered users and 2 guests