Golang builtin.append() function example
package builtin
The append built-in function appends elements to the end of a slice. If it has sufficient capacity, the destination is resliced to accommodate the new elements. If it does not, a new underlying array will be allocated. Append returns the updated slice. It is therefore necessary to store the result of append, often in the variable holding the slice itself:
Golang builtin. append() function usage example
package main
import "fmt"
func main() {
slice1 := []string(nil)
fmt.Println("slice1 has elements of ", slice1)
slice1 = append(slice1, "a")
fmt.Println("After append, now slice1 has elements of ", slice1)
}
Output :
slice1 has elements of []
After append, now slice1 has elements of [a]
Reference :
Advertisement
Something interesting
Tutorials
+6.2k PHP : How to handle URI or URL with non-ASCII characters such as Chinese/Japanese/Korean(CJK) ?
+5.4k Golang : Reclaim memory occupied by make() example
+19.2k Golang : Delete item from slice based on index/key position
+5.4k Unix/Linux/MacOSx : How to remove an environment variable ?
+8.8k Android Studio : Image button and button example
+11.2k Google Maps URL parameters configuration
+7.1k Golang : Squaring elements in array
+7.5k SSL : How to check if current certificate is sha1 or sha2 from command line
+9.7k Golang : Populate slice with sequential integers example
+7.1k Golang : A simple forex opportunities scanner
+12.7k Golang : Send data to /dev/null a.k.a blackhole with ioutil.Discard
+5.7k Unix/Linux/MacOSx : Get local IP address