我是 Java 的新手,但我想将一个字符串拆分成多个字符并将它们存储在一个数组中,然后计算总字符数。到目前为止,这是我的代码。
公共(public)类主要{
public static void main(String []args){
String Example = "This is an example"; //String
String[] array = Example.split(",");
int totalLength = array.length();
System.out.println(totalLength);
}
最佳答案
你可以使用 String.toCharArray()
和类似的东西
String example = "This is an example"; //String
char[] array = example.toCharArray();
int totalLength = array.length;
System.out.println(totalLength);
关于java - 如何将字符串拆分为长度数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27848968/