A friendly place for Java greenhorns!
Java
Ranch
»
Big Moose Saloon
Search
|
FAQ
|
Recent Topics
|
Hot Topics
Register
/
Login
Java
Ranch
»
Forums
»
Professional Certification
»
Programmer Certification (SCJP)
Author
String doubt
Ashok Pradhan
Ranch Hand
Joined: Dec 17, 2007
Messages: 144
posted
Apr 28, 2008 22:09:00
in JLS It states that for any two strings s and t, s.intern() == t.intern() is true if and only if s.equals(t) is true.
public class Test1 { public static void main(String[] args) { String s="test"; String s1 = new String("test"); System.out.println(s1.intern()==s); //line 1 System.out.println(s.intern()==s1); //line 2 } }
OUTPUT
true
false
i am confusing why line 2 returns false.please explain it and thanks.
sridhar row
Ranch Hand
Joined: Jan 16, 2008
Messages: 161
posted
Apr 28, 2008 23:10:00
What do you want it to return? hint: You are using ==.
Ashok Pradhan
Ranch Hand
Joined: Dec 17, 2007
Messages: 144
posted
Apr 29, 2008 02:11:00
Thanks I get it.
Java
Ranch
»
Forums
»
Professional Certification
»
Programmer Certification (SCJP)
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
Contact Us
| Visit our
Java
home page!
Copyright © 1998-2009
Paul Wheaton
Powered by
JForum 2.1.8
©
JForum Team