You use == to compare string types. Use age.equals("30") instead.
EDIT : show his work
If you use this as a cond definition:
String cond = "age.equals(\"30\")";
Output:
sss30 success
In response to a question about using =="30" instead, here is the answer to this question:
If your String age interned because it is a compile-time constant, then this may be true.
final String age = "30";
However, if you are explicitly a new String , otherwise it is not interned, then it will be false.
String age = new String("30");
You can run both examples to see this in action. Perhaps you can get fail for both.
Now, just because internment exists does not mean that it should rely on it to compare String types. The == operator should only be used to compare primitives with each other and to compare reference types to see if they point to the same object, so for reference types we can say that it sees if two objects are identical instead of equal .
Sometimes, through the magic of the JVM and JDK, String and other primitive wrappers, such as Integer , may be comparable to == , but situations for this are limited and unreliable.
source share