Some months ago, I remember being in an interview and being asked for three different ways to compare strings in Java for their values. Out of curiosity, I'm going to ask it here for my own reference. I thought of two:
str1.equals(str2)
or usingcompareTo
, both counting as one in total- comparing character by character
Any idea? "==", equalsTo, compareTo, and any variations of them are not it I was told.
Edit: Fixed question a bit.