-5

I'm just wondering if anyone could answer a question for me? Would it be possible to take a string variable of 8 letters and then put each letter into a char array?
For example:

  String str;
  str = "ABCDEFGH";

Would you be able to take this string variable and split it into an array of 8 characters?

Update:
char[] charArray = str.toCharArray();
will do it
Exactly same question, answered here:
Split string into array of character strings

4

4 回答 4

9

怎么样:

String str = "ABCDEFGH"; 
char[] charArray = str.toCharArray();

阅读String类的文档。

于 2013-08-02T14:15:08.833 回答
2

是的,你可以,你可以使用toCharArray()方法。

String str = "ABCDEFGH";
char[] array=str.toCharArray();

请确保您阅读了javadoc

于 2013-08-02T14:19:34.553 回答
1

您已经在 String 类中有一个方法来执行此操作。

String str = "ABCDEFGH";
char[] array=str.toCharArray();
于 2013-08-02T14:22:19.767 回答
0
char[] arr=new char[8];
for(int i=0;i<str.length();i++)
{
arr[i]=str.charAt(i);
}
于 2013-08-02T14:14:46.503 回答