I can't understand why we need compared, equal method. What is the important reason to use it to compared variables ... | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I can't understand why we need compared, equal method. What is the important reason to use it to compared variables ...

4th Apr 2017, 10:26 AM
Sei
Sei - avatar
3 Answers
+ 3
to see if the two variable are equal, for example password? or when you do a console program that takes user input, and compare the input with the predefined options, then execute the code corresponding to the user input
4th Apr 2017, 11:45 AM
Heng Jun Xi
Heng Jun Xi - avatar
+ 3
if you are wondering why equal method exist, when == can so the task.... well... == is for reference comparison, equal method is for object comparison http://stackoverflow.com/questions/7520432/what-is-the-difference-between-vs-equals-in-java
4th Apr 2017, 11:49 AM
Heng Jun Xi
Heng Jun Xi - avatar
+ 1
Thank you Heng. Yeah.. A password should not be equal to others, and need comparison :0 I will read the page that you uploaded.
4th Apr 2017, 12:24 PM
Sei
Sei - avatar