equalsIgnoreCase() is faster than equals()
My intuition would tell me that String.equalsIgnoreCase() would be a more expensive operation than String.equals(). If you think about it you have a lot more combinations that you have to test. This is where reality diverges from intuition.
The first things that both String.equalsIgnoreCase() and String.equals() check is length, and I’m willing to bet that most strings aren’t the same length, so you’re done. The reality is that String.equalsIgnoreCase() may be faster in a lot of instances because its parameter is a String so it doesn’t need to check instance and cast before the length comparison like String.equals() who’s parameter is Object.
So don’t handicap your string comparison just because you’re worried about performance. With String.equalsIgnoreCase() you can be fast and flexible.
Tags: Java, performance




