0

== operator in jsp and Java

since jsp is basically Java only why shouldn't the '==' operator can't be used to compare between two Strings? enter code here if String name="SonGoku"; String name2="SonGoku"; in '**java**' **(name==name2)** is **true** in 'jsp' (name==name2) is not true why this difference is there ? should we always use ".equals()" in jsp ?

18th Aug 2018, 12:51 PM
Christy Alex
Christy Alex - avatar
2 Réponses
+ 2
I think .equals() is also the way to go for String comparison in Java, == only returns true if both name & name2 points to an identical object. Hth, cmiiw
18th Aug 2018, 12:56 PM
Ipang
+ 1
For string comparison, Java recommend you to use the == operator instead of the equals() method
19th Aug 2018, 2:44 AM
Christopher
Christopher - avatar