Saved Bookmarks
| 1. |
What is the difference between str1 == str2 and str1.equals(str2)? |
|
Answer» JAVA offers both the equals() method and the "==" operator for comparing objects. However, here are some differences between the two:
Example: public class StringComparison{ public STATIC void main(STRING[] args) { String str1=new String("Scaler"); String str2=new String("Scaler"); System.out.println(str1 == str2); System.out.println(str1.equals(str2)); }}Output: falsetrueIn this example, two different String objects are being created, str1 and str2.
|
|