java - Two string's which (I think) are identical do not return true when checking if the same -


this question has answer here:

i have 2 strings, 1 inputted user , 1 name of thread. inputted name should same thread. verify have program output

system.out.println("ds:" + deamonmain.threadnamefinal + "cn:" +getname()); 

which prints

ds:thread-66cn:thread-66 

now these appear same string. however, when have test validity of using

boolean factchecker = deamonmain.threadnamefinal == getname(); system.out.println(factchecker); 

it prints false...

why this? have getname()? how string different , why so?

you need use string.equals compare string equality, not == sign.

as in:

boolean factchecker = deamonmain.threadnamefinal.equals(getname()); 

the == operator checks reference equality, while equals method checks equality of string values.

see here older thread on matter.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -