Originally posted by Stefan Wagner: Theoretically, both will be even fast. Practically, you'll implement both methods, and run them a few million times, and see, which is faster.
"Theoretically, both will be even fast" doesn't answer my question. My question is if there is fundamental low level implementation difference that may make little difference in the speed.
I don't care what's the practical result. Even i find practically method 1 is faster than 2 by 5%, so what ? I want to know why... And that's why I am interested in knowing if their low level implementation may contribute to it, and that's why I posted it in "Advanced" forum. testing this practically is a junior topic.
Ultimately, both approaches end up looking at every character in the string until the desired character is found. That's as low-level as it gets. If you use a regex, you have the additional overhead of compiling the regex into a Pattern object and creating a Matcher object. Once that's done, the regex approach should be just about as fast as indexOf().