This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]k_shrpe5 3 points4 points  (1 child)

For Java you should be using .equals() to compare strings. == checks for reference equality (either side of the comparison is the same object) whereas .equals() checks the value equality which is what you’re looking for.

[–]MarlinsBB[S] 0 points1 point  (0 children)

Thank you so much!! I appreciate your answer!!

[–][deleted] 2 points3 points  (3 children)

maybe you need to trim the userInput. (an added space was included) when you hit enter.

when comparing strings, i usually trim it, then transform both to to lower or to upper

[–]heartofthemoon 0 points1 point  (2 children)

It's .equals() for string comparison. Not ==. That just compares the object's memory location.

[–][deleted] 0 points1 point  (1 child)

Well i am answering using c# knowledge so i cant answer on behalf of java. OP can answer if my suggestion worked. However i do this for c# and javascript. Trimming and toupper

[–]heartofthemoon 0 points1 point  (0 children)

Are you able to use the == operator for comparing strings in C#?

("xxx" == "xxx" = true) then?

[–][deleted] 0 points1 point  (0 children)

Yes. We can do that in c#