To change a string into an array
The Java.lang package has the String.Split () method, which typically splits a string in Java with split (), returning an array.
Special, escape character, must be added "\ \" (".") and "|" are both escape characters)
Example:
1. If you use "." As a separate word, it must be written as follows, String.Split ("\ \"), so that the correct separation can not be used String.Split (".");
2. If you use "|" As a separate word, must be the following wording, String.Split ("\\|"), so that the correct separation, can not be used String.Split ("|");
3. If you have more than one delimiter in a string, you can use the ' | ' As hyphens, such as, "acount=?" and UU =? Or n=? ", the three are separated out, you can use String.Split (" And|or ");
4, if you want to use the "\" character in the string, you also need to escape. First of all to express "AAAA\BBBB" This string should be used "AAAA\\BBBB", if you want to separate it should be so to get the correct results,
string[] aa = "AAA\\BBB\\BCCC". Split ("\\\\");
5, if it is "ABC" this string, it is directly
String string = "abc";
char [] Stringarr = String.tochararray (); Note The return value is a char array
6, if you want to return a byte array directly using the GetBytes method is ok: string string = "abc"; byte [] Stringarr = String.getbytes ();
Turn an array into a string
Use the Join function in StringUtils. Org.apache.commons.lang.StringUtils; Example: Stringutils.join (NULL) = Nullstringutils.join ([]) = "" "Stringutils.join ([null]) =" "String Utils.join (["A", "B", "C"]) = "abc" Stringutils.join ([null, "", "a"]) = "a" string[] str = {"1", "2", "A", "B"};//the array into characters String Stringutils.join (str)//The array is separated by commas into string stringutils.join (str, ",")
Java arrays and strings are converted to each other