Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+25 votes
asked in CSC211_Winter2018 by (1 point)

4 Answers

+14 votes

I think that:
"=" is used for assignment

"==" is used to compare if the values are equal or not but this will be true if both of the value point to the same memory location.

".equals" is also used to compare the object but they did not have to point to the same memory location. So it is usually used for compare 2 String.

answered by (1 point)
+13 votes

One equal sign is assigning a value, the double equal sign is testing if both values are equal to each other, .equals means setting a String equal to each other.

answered by (1 point)
+3

Small correction: the .equals() method is for testing whether Strings (or other objects) ARE equal to each other. It does not set one string equal to another one (you would still use = for that!)

+2 votes

you use == for boolean methods, and = for other types

answered by (1 point)
+1 vote

We use = when we assign variables.
We use == during integer Boolean comparisons such as if(a==3).
We use .equals during string Boolean comparison.

answered by (1 point)
...