Home > Java > javaTutorial > Usage of tochararray in java

Usage of tochararray in java

下次还敢
Release: 2024-05-01 18:45:43
Original
909 people have browsed it

The toCharArray() method in Java converts a string into a character array. It receives a string as argument and returns a character array containing the characters in the string.

Usage of tochararray in java

##In JavatoCharArray() Usage

toCharArray() is a method of the String class in Java, used to convert a string into a character array.

Usage:

<code class="java">char[] charArray = string.toCharArray();</code>
Copy after login
Among them,

string is the string to be converted, charArray is the converted character array .

Example:

<code class="java">String str = "Hello World";
char[] charArray = str.toCharArray();

System.out.println(Arrays.toString(charArray));</code>
Copy after login
Output:

<code>[H, e, l, l, o,  , W, o, r, l, d]</code>
Copy after login

Note:

    in character array Each element of is the Unicode value of the corresponding character in the string.
  • The original string will not be modified.
  • If the string is
  • null, a NullPointerException exception will be thrown.

The above is the detailed content of Usage of tochararray in java. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template