Tuesday, May 8, 2012

Diffrence between == and equals


Many Java beginners find it difficult to differentiate between == operator and the “equals()” method when comparing String variables in Java. They assume that both operations perform the same function and either one can be used to compare two string variables. I have even seen many experienced programmers committing the mistake of using “==” to compare the values of two strings.
So what is the difference between “==” and “equals()” and what is the correct method of comparing two string variables?


No comments:

Post a Comment