I am fairly new to java, and I cannot figure out for the life of me why this piece of code is not working, I am trying to see if a word is an adverb, and hence if it ends in "ly" or not (they will always be lowercase). This is my code:
String str = "evenly";
int a = str.length()-2;
int b = str.length();
String res = (String)str.substring(str.length()-2,str.length());
System.out.println(res + " == ly -> " + (res == "ly"));
I am testing it here: http://ideone.com/4FuBwj
The output is: ly == ly -> false
Which means that, res = "ly"
but res == "ly"
is false
?
Why is this happening?