A friendly place for Java greenhorns!
Java
Ranch
»
JavaRanch Saloon
Search
|
FAQ
|
Recent Topics
|
Hot Topics
Register
/
Login
Win a copy of
Pro JPA 2: Mastering the Java Persistence API
this week in the
Object Relational Mapping
forum!
Java
Ranch
»
Forums
»
Professional Certification
»
Programmer Certification (SCJP)
Author
String doubt
Ashok Pradhan
Ranch Hand
Joined: Dec 17, 2007
Messages: 145
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: 162
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: 145
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