This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes String s = new String().equals( . . . . ) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String s = new String().equals( . . . . )" Watch "String s = new String().equals( . . . . )" New topic
Author

String s = new String().equals( . . . . )

Mathew Kuruvilla
Ranch Hand

Joined: Nov 27, 2001
Posts: 135
public class Test{
public static void main(String argv[]){
Test h = new Test();
h.go();
}
public void go(){
String s1 = "Hello";
String s2 = null;
if (s1.equals(s2))
System.out.println(true);
else
System.out.println(false);
}
}
This is giving me "false". Shouldn't I be getting "java.lang.NullPointerException"???
parul patidar
Ranch Hand

Joined: Sep 07, 2001
Posts: 53
no. see code for equals method

[This message has been edited by parul patidar (edited December 06, 2001).]
Mathew Kuruvilla
Ranch Hand

Joined: Nov 27, 2001
Posts: 135
Muchas Gracias Senor!
Dhanyawadh Guruji!
Thank you Sir!
 
Don't get me started about those stupid light bulbs.
 
subject: String s = new String().equals( . . . . )
 
Similar Threads
compare objects
== with Strings is giving a different result
one more with Strings ( == and equals)
Two ways to construct a String/pool of strings problem
Technical Interview Questions