In Java strings should not be compared with the == operator, instead you should use the equals() method so
str == "ld"
becomes
str.equals("id")
I will leave you to google it for an explanation.
Apart from that congratulations on a nice implementation.