• Post Reply Bookmark Topic Watch Topic
  • New Topic

Comparing Strings  RSS feed

 
Kristian Ledung
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!
I am comparing two Strings with each other and have noticed that
is faster than . Is that correct and why is that so?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can take a look at the source code of equalsIgnoreCase - it's coming with the JDK.

In short, equalsIgnoreCase only converts those characters which aren't equal each other already (so for two equal strings whith the same case, it doesn't need to convert any character). And it stops immediately when two characters aren't equal (so for two longs strings that already differ at the first character, only those two characters need to be converted).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!