Use equals()
method instead of ==
operator as below...
if (getIntent().getExtras().getString("thetext").equals( "amruta")) {
tv.setText("girl");
} else {
tv.setText("not a girl");
}
You can also use equalsIgnoreCase()
method.
Instances of String
are objects, so you can't compare two objects with ==
operator. The ==
operator is used to compare to primitive type data. To compare two String
, you have to use equals()
or equalsIgnoreCase()
method.