The examples in this article describe the conversion methods for char arrays (character arrays) and string strings in Java. Share to everyone for your reference, specific as follows:
When you are programming in the Java language, when you use the Password field JPasswordField component, you need to use the GetPassword () method of that component if you want to obtain a password value. JPasswordField's GetPassword () method returns an array of char types, which we often need to convert 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, you will often encounter situations where you convert a string type to a char array.
The following code, is relatively the most concise.
Cases:
String Strstringtype= "my string"; Create a String variable Strstringtype
char[] chrchararray;//Create a character array chrchararray
Chrchararray = Strstringtype.tochararray (); Converts a string variable to a character array
strstringtype= string.valueof (Chrchararray);//Convert a character array to a string
Here, the key is two methods.
(1) The ToCharArray () method of the String class, which converts a string to a character array
(2) The valueof () method of the String class converts an array of type char to a string
I hope this article will help you with Java programming.