Quelle est la longueur d’une chaîne ?

Comment trouver la longueur d’une chaîne en Java ?
Java fournit une méthode simple et pratique pour calculer la longueur de n'importe quelle String . Sans plus tarder, regardons un exemple de recherche de longueur de chaîne .Exemple
public class StringLength {
public static void main(String args[]) {
String alphabetsWithSpaces = "A B C";
String digitsWithSpaces = "1 2 3";
String specialCharsWithSpaces = "! @ $";
String allChars = "Z X 3 $$$ ^^^ * )(";
String sentence = "Hey, it's finally summers!";
System.out.println(alphabetsWithSpaces + " length = " + alphabetsWithSpaces.length());
System.out.println(digitsWithSpaces + " length = " + digitsWithSpaces.length());
System.out.println(specialCharsWithSpaces + " length = " + specialCharsWithSpaces.length());
System.out.println(allChars + " length = " + allChars.length());
System.out.println(sentence + " length = " + sentence.length());
}
}
Sortir
ABC longueur = 5 1 2 3 longueur = 5 ! @ $ longueur = 5 ZX 3 $$$ ^^^ * )( longueur = 23 Hé, c'est enfin l'été ! longueur = 26
GO TO FULL VERSION