Conversion method between char array (character array) and string type in Java

This article describes the conversion method between char array (character array) and string type in Java. Share with you for your reference, as follows:

When programming in the Java language, When using the "password field" jpasswordfield component, if you want to obtain the password value, you need to use the component's getpassword() method. Jpasswordfield's getpassword() Method returns an array of char type. We often need to convert this array to string type for operations such as password matching or password assignment. At this point, you need to convert an array of type char. Of course, we often encounter the case of converting string type to char array.

The following code is relatively the most concise.

Example:

String strStringType="my string"; //创建一个字符串变量strStringType
char[] chrCharArray; //创建一个字符数组chrCharArray
chrCharArray = strStringType.tocharArray(); //将字符串变量转换为字符数组
strStringType= String.valueOf(chrCharArray ); //将字符数组转换为字符串

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>