Welcome to the CSC Q&A.
Get help and give help!
Write great code!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+23 votes
asked in CSC211_Winter2018 by (8 points)

4 Answers

+13 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 (4.2k points)
+12 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 (8 points)
+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!)

+1 vote

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

answered by (8 points)
0 votes

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 (8 points)
...