I've C code that use a lot of commands identified by static string constants.
static char* KCmdA = "commandA"
static char* KCmdB = "commandB"
static char* KCmdC = "commandC"
In C I can compare two strings with strcmp(A, B) for example but as I only refer those command via their static string identifier it's faster to only check for pointer inequality since I know my unknowCMD can only be a pointer to one of my static strings.
switch(unknowCMD)
{
case KCmdA:
...
case KCmdB:
...
}
I guess in Java the equivalent to strcmp would be the method equals:
unknowCMD.equals(KCmdA)
Is there an equivalent of the pointer equality in Java ? I know Java uses only references. Is it possible to use those references for equality test without actually comparing the strings ?
Sorry if this is obvious I've check the doc but did not find any definitive answer.
if you compare equality of string refrences Use ==
if(str1==str2){
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With