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

+18 votes

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

asked in CSC211_Winter2018 by (1 point)

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 (1 point)
+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 (1 point)
...