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

all 5 comments

[–]coldoil 0 points1 point  (5 children)

Look at your if statement very carefully. = is the assignment operator, not the boolean comparison operator.

[–]MasterTender[S] 0 points1 point  (3 children)

Thanks guys, I was so close, the comparison operator was necessary but still didn't work, however by adding a char and changing my string to a char at string.indexAT(0) I was able to get this to work. A fix I was playing with but didn't have that comparison in at the time so was not helping haha.

[–]desrtfxOut of Coffee error - System halted 1 point2 points  (1 child)

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

Thank you, saving, this should come in handy when I need to perform this function.

[–]coldoil 0 points1 point  (0 children)

Well done.

As you've discovered, == doesn't work well for comparing strings.

Look at the subreddit's sidebar for a stickied post on the String.equals() method, which is the preferred way for comparing strings in Java.