This is a weird behavior I found with Java's String.indexOf()
and String.contains()
methods. If I have a non-empty string says blablabla
and I try to look for an empty string inside it, it always returns true
whereas I would expect it to return false
.
So basically, why does the code below return true and 0 ?
String testThis = "";
String fileName = "blablablabla";
System.out.println(fileName.contains(testThis));
System.out.println(fileName.indexOf(testThis));
Logically (at least to me) ""
does not occur in blablablabla
but indexOf("")
says it does, why?