méthode Java startsWith ()
Procédé startsWith () est utilisée pour détecter si la chaîne de caractères commence par le préfixe spécifié.
grammaire
public boolean startsWith(String prefix, int toffset) 或 public boolean startsWith(String prefix)
Paramètres
préfixe - le préfixe.
toffset - la chaîne pour lancer la recherche.
Valeur de retour
Si la chaîne avec le début préfixe spécifié, retourne vrai, sinon faux.
Exemples
public class Test { public static void main(String args[]) { String Str = new String("www.w3big.com"); System.out.print("返回值 :" ); System.out.println(Str.startsWith("www") ); System.out.print("返回值 :" ); System.out.println(Str.startsWith("w3big") ); System.out.print("返回值 :" ); System.out.println(Str.startsWith("w3big", 4) ); } }
Les résultats de l'exécution du programme ci-dessus:
返回值 :true 返回值 :false 返回值 :true