Skip to content

Instantly share code, notes, and snippets.

@tomtsang
Created February 14, 2018 05:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomtsang/8d6c69ef418b7e090024b0266276fb81 to your computer and use it in GitHub Desktop.
Save tomtsang/8d6c69ef418b7e090024b0266276fb81 to your computer and use it in GitHub Desktop.
slice-2.go
package main
import (
"fmt"
)
func main() {
array1 := [...]string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"}
slice1 := array1[2:6]
fmt.Println(slice1)
slice1 = slice1[:cap(slice1)]
fmt.Println(slice1)
fmt.Println(array1)
fmt.Println("----------")
slice5 := array1[2:6:8]
fmt.Println(slice5)
fmt.Println(cap(slice5), len(slice5))
slice5 = slice5[:cap(slice5)]
fmt.Println(slice5)
slice5 = append(slice5, []string{"k", "l", "m", "n"}...)
fmt.Println(slice5)
fmt.Println(array1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment