Javaで文字列の文字数を確認するにはどうすればよいですか?[複製]
Aug 21 2020
これは簡単な質問ですが、私は研究があまり得意ではありません。
aの文字数を調べてString
、int
変数に入れようとしています。例えば:
String word = "Hippo";
int numOfCharacters = (the code that tells me how many characters in the word);
そして、後でその番号を使用します。
回答
3 JustAnotherDeveloper Aug 21 2020 at 17:53
関連するJavadocはそれを教えてくれますlength()
あなたが探している方法です。したがってword.length();
、のサイズが返されword
ます。これは、必要なサイズです。
2 SorinCertan Aug 21 2020 at 18:00
.length()を使用して、文字列の文字数を取得します
String word = "Hippo";
int numOfCharacters = word.length();