List, Set, array, and so on

Source: Internet
Author: User
Tags array to string

Dependent jar Package: Xwork-core-2.1.6.jar


Import java.util.ArrayList;

Import Java.util.HashSet;
Import java.util.List;
Import Java.util.Set;
Import Org.apache.commons.lang.xwork.StringUtils;

/**
* List, Set, array-round string
* @author RSun
* @Date 2012-11-01
*/
public class Test {

public static void Main (string[] args) {


String str = "";

List Spin string
list<string> list = new arraylist<string> ();
List.add ("A");
List.add ("B");
List.add ("C");
str = Stringutils.join (List.toarray (), ","); Returns a string based on different cutting characters
System.out.println ("Normal list conversion:" + str);
List.clear ();
str = Stringutils.join (List.toarray (), ",");
SYSTEM.OUT.PRINTLN ("size is 0 conversion:" + str);

String array to String
String[] Strarray = {"AA", "BB", "CC", "DD"};
str = Stringutils.join (Strarray, "-");
System.out.println ("Normal array conversion:" + str);

Strarray = new String[3];
str = Stringutils.join (Strarray, "-");
System.out.println ("Special array Conversion:" +STR);

Integer reference type spin string

integer[] array = new INTEGER[3];
Array[0] = 1;
ARRAY[2] = 2;
str = stringutils.join (Array, "-");
System.out.println ("Integer Conversion:" +STR);

Set converted to string
set<string> set = new hashset<string> ();
Set.add ("AA");
Set.add ("BB");
Set.add ("CC");
str = Stringutils.join (Set.toarray (), ";");
System.out.println ("Special array Conversion:" +STR);


}

}

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.