Use the join function in StringUtils. org . Apache . commons . lang . string utils; Example:
StringUtils.join (empty)? = empty
StringUtils.join([])? = ""
StringUtils.join([null])? = ""
StringUtils.join(["a "," b "," c"]) = "abc "
StringUtils.join([null,""," a"]) = "a "
String[] str = { " 1 "," 2 "," a "," b " };
//Convert an array to a string
StringUtils.join(str)
//Converts a comma-separated array into a string.
StringUtils.join(str,",")
Method for convert a string into an array:
There is a String.split () method in the java.lang package. Split () is often used in java to split strings and return an array.
Special escape characters, you must add "\" (."and" | "are escape characters).
Example:
1. If "."is used as a delimiter, it must be written as follows, String.split("\\. ") so that it can be separated correctly, instead of String.split (".");
2. If "|" is used as the separator, it must be written as String.split("\\| ") so as to separate it correctly, instead of string. Split ("| ");
3. If there are multiple separators in a string, you can use "|" as a hyphen, for example, "acount=? And uu =? Or n=? " , to separate the three, you can use string.split ("and | or");
4. If you want to use the "\" character in the string, you need to escape it. First of all, you should use "aaaa\\bbbb" to represent the string "aaaa\bbbb". If you want to separate it, you should get the right result.
String[] aa = "aaa\\bbb\\bccc "。 Split ("\ \ \");
5, if it is a string like "abc", directly.
String string = "abc "
;
char[]string ar =
string . tochararray(); //Note that the return value is a char array.
6. If you want to return a byte array, just use the getBytes method directly.
& ltspan style="white-space:pre " >& lt/span>。 String string = " abc
& ltspan style="white-space:pre " >& lt/span>。 byte[]string ar = string . getbytes();