[Solved] unable to get the expected output,i should get true but when executed i am getting false?


you just need to change you code likewise,

if(str.substring(1,3).equals(a)){...}

what you did wrong is ,

you have been used ‘==’ assignment operator,

it is not comparing content(here, string) instead of it, it compare’s
memory location between two compared string.

it’s obvious to get false, because how is it possible ? that two
different string refer to same memory-location.

so this is all about ‘==’ relational-operator does.

if you use ‘equals(..)’ then it is compares string unlike
memory-location(==).

solved unable to get the expected output,i should get true but when executed i am getting false?