• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String comparision Doubt

 
Revathy Balajee
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please see the below code, When I run this what ever i have typed in double quotes in System.out.println is not printing and also the second SOP should print as true but it is printing as false why is that?


But the same code if I just modify a bit in SOP with those extra brackets added prints the text as well prints correctly the value as true.

 
Les Morgan
Rancher
Posts: 710
17
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're getting an evaluation problem here. The String + String is being evaluated, then the comparison is done, until you set the precedence grouping differenctly by using the parenthesis where you then get String + Boolean. In Java's order of precidence String concatenation comes before a comparison, but the parenthesis force the grouping you are looking for.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic