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.


+18 votes

Whats the difference between,
if (name.equals("blue"));
if (name=="blue")

asked in CSC211_Winter2018 by (8 points)

2 Answers

+14 votes

if(name.equals("blue")) it is testing the string if it is equal and that would right.
if(name=="blue") is only for int and doubles .equals and it is a test not assigning, but the correct way you would .equals because it is a string.

answered by (8 points)
+6 votes

When dealing with integers and strings there are some differences; such that when using the if statement you have to put the .equals("something") syntax.

answered by (8 points)