Title is the entire question. Can someone give me a reason why this happens?
Java – Why does “abcd”.StartsWith(“”) return true
cjavastartswith
Related Topic
- C# – Case insensitive ‘Contains(string)’
- Javascript – How to check if a string “StartsWith” another string
- Java – Does Java support default parameter values
- Java – Why is subtracting these two times (in 1927) giving a strange result
- Java – Why don’t Java’s +=, -=, *=, /= compound assignment operators require casting
- Java – Why is processing a sorted array faster than processing an unsorted array
- Java – Why is printing “B” dramatically slower than printing “#”
- C# – Making a cross-thread call to a ListView
Best Answer
Yes - because it does begin with the empty string. Indeed, the empty string logically occurs between every pair of characters.
Put it this way: what definition of "starts with" could you give that would preclude this? Here's a simple definition of "starts with" that doesn't:
"x starts with y if the first
y.Length
characters of x match those of y."An alternative (equivalent) definition:
"x starts with y if
x.Substring(0, y.Length).Equals(y)
"