This article describes the conversion method of char array (character array) and string String type in Java. Share it for your reference, as follows:
When programming in Java language, when using the "password field" jPasswordField component, if you want to obtain the password value, you need to use the getPassword() method of the component. jPasswordField's getPassword() method returns an array of char type. We often need to convert this array to String type to perform operations such as password matching or password assignment. At this time, you need to convert an array of char type. Of course, you often encounter situations where you convert String type to char array.
The following code is relatively simple.
example:
String strStringType="my string"; //Create a string variable strStringTypechar[] chrCharArray; //Create a character array chrCharArraychrCharArray = strStringType.toCharArray(); //Convert a string variable to a character array strStringType= String.valueOf(chrCharArray); //Convert a character array to a string
Here, there are two key methods.
(1) String class toCharArray() method, converts strings to character arrays (2) String class valueOf() method, converts char-type arrays to strings
I hope this article will be helpful to everyone's Java programming.