どうも、ちょげ(@chogetarou)です。
文字列(string)の長さを取得する方法を紹介します。
方法

文字列(string)の文字数を取得するには、length()を使います。
具体的には、str.length()
のように、文字列からlength()を呼び出します。
int length = text.length();
length()は、呼び出した文字列の文字数を取得します。
使用例
public class Main {
public static void main(String[] args) throws Exception {
String text = "Hello,World";
int length = text.length();
System.out.println(length);
}
}
出力:
11
コメント