Java – which is faster, equalsignorecase or comparetoignorecase
•
Java
In a Java application, suppose I can choose the following comparison method
equalsIgnoreCase(String anotherString)
compareToIgnoreCase(String str)
Which is faster?
Solution
Equalsignorecase can be much faster For example, consider two strings that start with the same 10000 characters - but one of the strings ends with an extra character Equalsignorecase can return immediately; Comparetoignorecase must iterate to the end of the string to see the difference
But generally speaking, I will choose to better express your intention This is also good for performance: suppose I say equalsignorecase is at least as fast as comparetoignorecase, which means you should use it as much as possible - if you need actual sorting, you must use comparetoignorecase
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码