When comparing objects in java that are not primitive data types (int, char, boolean, etc...
), you have to use the method Object#equals(Object)
, which returns a boolean.
So, when you are comparing two Strings, you are actually checking if the two Objects are the same instance, instead of the actual value.
All you have to do is just change name == cname
to name.equals(cname)
.