Golang (Go language) Append of built-in functions

Source: Internet
Author: User
Append is primarily used to append elements to a slice (slice)
If the tile storage space (CAP) is sufficient, it is added directly, the length (len) is longer, if there is not enough space, the memory is re-opened and the previous element is copied with the new element. The first parameter is a slice, followed by the variable parameter base usage of the slice storage element type:
Slice: = Append ([]int{1,2,3},4,5,6) fmt. Println (Slice)//[1 2 3 4 5 6] The second parameter can also be directly written to another slice, appending all of its element copies to the first slice. It is important to note that the parameters of this usage function can only receive two slice and add three points to the end
Slice: = Append ([]int{1,2,3},[]int{4,5,6} ...) fmt. Println (Slice)//[1 2 3 4 5 6] There is also a special use of the string as a []byte type as the second parameter passed in
Bytes: = Append ([]byte ("Hello"), "World" ...) the return value of the APPEND function must have a variable to receive, or the compiler will error, for specific reasons please refer to: http://blog.csdn.net/qq245671051/ article/details/50722823


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.