Java String.toCharArray()

Syntax

String.toCharArray() has the following syntax.

public char[] toCharArray()

Example

In the following code shows how to use String.toCharArray() method.


import java.util.Arrays;
/*from   w  w w .  j  a  va 2 s  .co  m*/
public class Main {
  public static void main(String[] argv) {
    String str = "java2s.com";
    char[] chars = str.toCharArray();
    System.out.println(Arrays.toString(chars));
  }
}

The output:





















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable