Conversion of arrays and strings

Source: Internet
Author: User

Conversion of arrays and strings

Looks like the array needs to be a string to fit into the database

So

First, the conversion of arrays and strings in JS

Array variable string var a, B; Two variables an array a a string b

A=new array{0,1,2,3,4,5};

B=a.join ("-"); b= "0-1-2-3-4-5" js inside the array into a string with the array name. Join ("-");

String variable group var b= "0-1-2-3-4-5";

var a=b.split ("-"); In-decomposition js inside the string variable group uses a string. Split ("-");

Second, the use of the list array in Java code

1 Converting a list collection to a list array

List<a> Alist=aservice.getbyid (IDs);//from the database according to the ID of a collection put to the list collection, A is an entity

List<string> blist=new arraylist<string> (); Create a list array to put a number

For (a a1:alist) {

Blist.add (A1.getano ());                            Places the number of a in the list collection into List array B. list's. Add Usage

}

2 Converting a list array into a string array

String [] a=new string[blist.size ()]; Creates an array of type string generic collection. Size array. length string. Length ()

Blist.toarray (a);//Convert list array to list array of string array--"string ToArray for Arrays

3 putting a string string into a string array

String s1= "AAAAA";

String s2= "BBBBB";

String s3= "CCCCC";

Arraylist<string> slist=new arraylist<string> (); List array

Slist.add (S1);

Slist.add (S2);

Slist.add (S3);

String [] str=new string[slist.size ()];

Slist.toarray (str);

4 array-"string introduced into the Apache Commons component of the Commons-lang.jar package in the Apache Commons component of the Commons-lang.jar package

String [] a={"abc", "D", "EF"};

String Str=stringutils.join (A, "-");                                                                                 Stringutils.join next detail

5 Array--"string String.Format () method String.Format () method The next article detailed

String Str=string.format ("%s,%s,%s", a);

6 array-"string traversal stitching StringBuffer stringbuffer inside the Append Method next detail to get

StringBuffer sb=new StringBuffer ();

for (in i=0;i<a.length;i++) {

Sb.append (A[i]);

}

String strn=sb.tostring ();

      

            

Conversion of 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.