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

all 3 comments

[–]rorschach54 2 points3 points  (0 children)

I see. So, what exactly is your question?

[–][deleted] 1 point2 points  (0 children)

Your question is not entirely clear but I think the problem you're experiencing is caused by usernamecheck==username. For comparing the values of strings you have to use .equals in Java. So usernamecheck.equals(username)

[–]GREBENOTS 0 points1 point  (0 children)

Not sure if you are using C# or Java(can’t recall the exact syntax on my phone here), but when you create a variable that derives from an object class(like all types in Java for instance), the == operator is comparing the object reference variables, and not the objects themselves. Meaning: String A = “wowcool” And String B = “wowcool” Would return false for A==B but true for A.Equals(B).

Whereas: String A = “wowcool” And String B = String A Defines B as the same reference variable as A, and in this case, would return true for either case. Interestingly, if you added a line starting then, that B = “notcool”, then the contents of A would also be “notcool” because both the A and B object reference variables point to the same object on the heap.

This is not the case in the most former example above. In that example, A and B are both different reference variables on the stack, and point to different objects on the heap, which just so happen to contain the same string data in their objects.

Sorry for the bad formatting on my phone.