String product = Integer.toString(w);
char[] original = String.toCharArray(product);
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止的代码.错误说我不能在String上使用toCharArray,但我查看了文档,这是一个列出的方法,所以我有点卡住了.
product.toCharArray()
toCharArray不是一个静态方法,而是一个已经存在的字符串的方法,这就是为什么它不能为你编译的原因.
这是一个较长的例子:
public class ToCharArrayString {
public static void main(String args[]) {
//method converts complete String value to char array type value
String str = " einstein relativity concept is still a concept of great discussion";
char heram[] = str.toCharArray();
// complete String str value is been converted in to char array data by
// the method
System.out.print("Converted value from String to char array is: ");
System.out.println(heram);
}
}
Run Code Online (Sandbox Code Playgroud)