Conversion of string arrays and strings

Source: Internet
Author: User

1.stringutils.join (Object array[],string separator)

Make the array a new string as a symbol or other string interval

Object array[] The array to convert. Separator the interval symbol that makes up a new string, such as "," "|"

private static final string[] str = {"1", "2", "3", "4"};2 String str2 = Stringutils.join (str, "|"); 3 4 System.out.println (STR2);

output Result: 1|2|3|4

Reprinted from: https://www.cnblogs.com/astrocc/archive/2012/10/20/2732733.html

The Spit () method in 2.java

Basic format:stringobj.split ([separator,[limit]]) parameter, where each part,stringobj This represents the string to be split,separator represents the a string or regular expression object that identifies whether one or more characters are used when separating the string. If this option is omitted, a single element array containing the entire string is returned; Limit : Indicates that the value is used to limit the number of elements in the returned array.

This method returns an array of strings, If a special character is encountered, such as a regular expression, for example: | , + , * , ^ , $ , / , | , [ , ] , ( , ) , - , . , \

For example, to use | Vertical bar to split a character, because |                itself is a part of the regular expression, so need \ to escape, because the escape using \, and this \ is exactly the character of the regular expression, so you have to use a \, so need two \ \. If you use "." As a separate word, it must be written as follows: String.Split ("\ \"), if the "|" As a separate word, it must be written as follows: String.Split ("\\|"), If there is more than one delimiter in a string, you can use the "|" As a hyphen, for example: "A=1 and b =2 or c=3", the three are separated out, you can use the String.Split ("And|or");

2. String array converted to string

Example:

string[] str = {"abc", "BCD", "def"}; StringBuffer sb = new StringBuffer (); for (int i = 0; i < str.length; i++) {SB append (Str[i]);} String s = sb.tostring ();

If it is a "character array" to "string"

char[]   data={' A ', ' B ', ' C '};   String  s=new   string (data);

Transferred from: https://www.cnblogs.com/SharkBin/p/4512561.html

Conversion of string arrays and strings

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.