In java, you can use the toCharArray() method to convert a string into a char character array. The syntax format is "String variable.toCharArray()" and the return value is a character array.
The operating environment of this tutorial: windows7 system, java8 version, DELL G3 computer.
Use .toCharArray() in java to convert a string into a character array
package com.oracle; import java.util.Scanner; public class Test { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); String str=input.next(); char ss[] = str.toCharArray();//利用toCharArray方法转换 for (int i = 0; i < ss.length; i++) { System.out.println(ss[i]); } } }
The toCharArray() method converts a string into a character array. Syntax:
public char[] toCharArray()
Parameters
None
Return value
Characters array.
Recommended related video tutorials: Java video tutorial
The above is the detailed content of How to convert string to char array in java. For more information, please follow other related articles on the PHP Chinese website!