如何找出 Java 中的字符串中的字符数?

How can I find out the number of characters in a String in Java?

这个问题很简单,但我不是很会研究

我试图找出 String 中的字符数并将其放入 int 变量中。例如:

String word = "Hippo";
int numOfCharacters = (the code that tells me how many characters in the word);

以后再用那个号码。

relevant JavaDoc 会告诉您 length() 是您正在寻找的方法。所以 word.length(); 会 return word 的大小,这就是你想要的。

使用.length()获取字符串中的字符数

  String word = "Hippo";
  int numOfCharacters = word.length();