Creation and initialization of swift--arrays

Source: Internet
Author: User

1Let array1 = ["ABC","EFG"]2Let array2 = ["CCC",4]4 println (array2);5 6 vararray3:string[]=["ABC","DDD"]//the array type is specified. Requires that each array element be a string. 7 8Let array4:string[] =array19 Tenarray1[0] ="XYZ" One  Aprintln (ARRAY4)//XYZ,EFG -   - varIntarray = int[] ()//Create an int type the  - varFourInts1 = int[] (count:4, Repleatedvalue:2) -  - varStrArray1 = ["ABC","BB"] + varStrArray2 = ["XXX","yyy"] - varStrarray = StrArray1 +StrArray2 +println (Strarray)//[abc,bb,xxx,yyy] is not the addition of each array element, the type of each array element must be identical when added.  A  at  -strarray1[0...1] = ["XYZ","DDD"] -println (StrArray1)//[XYZ,DDD] -strarray2[0..1] = ["XYZ","DDD"] -println (StrArray2)//[XYZ,DDD,XYZ] Three points are left closed right closed. Two points indicate left closed right open, XYZ inserted in the position of XXX, but ddd no place, so inserted in the second element xyz front (the value of the assignment is more than the index, will be inserted in the back of the Element). If you need to assign the correct value, change it to strarry2[0..2]. 

Three points: Closed interval

Two points: Left closed right open interval

1 strarray1[0... 1] = ["xyz","ddd","UUU"  ]2 println (strArray1)   //[xyz,ddd,uuu]  3 4 in front of only two assignments, then the last number will be inserted into the final position, forming a third element.

Creation and initialization of swift--arrays

Related Article

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.