indexOf Case Sensitive?

Brian picture Brian · Jul 14, 2009 · Viewed 109.6k times · Source

Is the indexOf(String) method case sensitive? If so, is there a case insensitive version of it?

Answer

Joey picture Joey · Jul 14, 2009

The indexOf() methods are all case-sensitive. You can make them (roughly, in a broken way, but working for plenty of cases) case-insensitive by converting your strings to upper/lower case beforehand:

s1 = s1.toLowerCase(Locale.US);
s2 = s2.toLowerCase(Locale.US);
s1.indexOf(s2);