K
kaeli
If I have a string and I don't know the letter case, and I wish to compare it
to a known string of known case, which of these methods is more efficient?
The string is (would be) in the variable "myStr" and we do not know if it is
null and we do not know the case of the letters.
A:
if ("VALUE".compareToIgnoreCase(myStr) == 0) {
// do something
}
B:
myStr = myStr==null?null:myStr.toUpperCase()
if ("VALUE".equals(myStr)) {
// do something
}
Even more efficient code than either of these two welcome.
--
to a known string of known case, which of these methods is more efficient?
The string is (would be) in the variable "myStr" and we do not know if it is
null and we do not know the case of the letters.
A:
if ("VALUE".compareToIgnoreCase(myStr) == 0) {
// do something
}
B:
myStr = myStr==null?null:myStr.toUpperCase()
if ("VALUE".equals(myStr)) {
// do something
}
Even more efficient code than either of these two welcome.
--