• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doesn't print the statement in System.out.println

 
Raju Sri
Ranch Hand
Posts: 108
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Can any body tell me why the following code doesn't print "TO JAVA: false".
--------------------------
String h1="hello";
String h2=new String("hello");
System.out.println("WELCOME");
System.out.println("TO JAVA:"+h1 == h2);
System.out.println("CERTIFICATION");
----------------------------------
I thought the program should print like below
WELCOME
TO JAVA:false
CERTIFICATION
But when I run the code it is not printing "TO JAVA" statment .
Thanks in advance
Raju
 
Vijay Pawar
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear shrini,
The rule is :
Operand 1 + Operand 2
If Operand 1 is a String then + will behave as concatination operator
and result will be a String
"To JAVA:" + h1 == h2 will be executed as
"To Java: hello" == h2
and the result u know is false
Bye
Jughead
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic