String s1 = "The quick brown fox jumps over the lazy dog";
String s2 = "";
boolean b = s1.contains(s2);
System.out.println(b);
I run the Java code above, the b return true.
Since s2 is empty, why does s1 contains s2?
I check the Java API, it write:
Returns true if and only if this string contains the specified sequence of char values.
Parameters:
s – the sequence to search for
Returns:
true if this string contains s, false otherwise
Empty is a subset of any string.
Think of them as what is between every two characters.
Kind of the way there are an infinite number of points on any sized line…
(Hmm… I wonder what I would get if I used calculus to concatenate an infinite number of empty strings)
Note that “”.equals(“”) only though.