today, when I read the Java Code , I saw that one of the methods of the string was startswith (string Str, is it easy, and then I did it myself. I did not expect to find a startswith () method overload, startswith (string STR, int index ), at that time, I went online to check whether this method was followed, so I did a test myself. Now I will give the following detailed explanation: startswith (string Str) it is to check whether the parameter is the same as the start of the string you want to check, while startswith (sring STR, int index) is to compare the specified subscript of the original string you want to compare with the parameter, here Str. startswith (string Str) and Str. startswith (string STR, 0) is no different. Let's look at the code below!
String ST1 = "dsadas ";
System. Out. println ("ST1:" + st1.startswith ("sa", 1 ));
String st2 = "dsadas ";
System. Out. println ("ST1:" + st2.startswith ("sa "));
String st3 = "dsadas ";
System. Out. println ("st2:" + st3.startswith ("ds "));
String st4 = "dsadas ";
System. Out. println ("st4:" + st4.startswith ("ds", 0 ));
String ST5 = "dsadas ";
System. Out. println ("ST5:" + st5.startswith ("ds", 1 ));
Output result:
ST1: True
ST1: false
St2: True
St4: True
ST5: false