Go语言的切片slice基本操作
2017-06-30 10:20
831 查看
感觉比数组好用,首选。
package main import ( "fmt" ) //main is the entry of the program func main() { slice1 := make([]string, 5) slice2 := make([]int, 3, 5) slice3 := []string{"Red", "Blue", "Green"} slice4 := []int{10, 20, 30} slice4[1] = 1000 slice5 := []string{9: ""} var slice6 []int slice7 := []int{10, 20, 30, 40, 50} newSlice := slice7[1:3] newSlice[1] = 35 newSlice = append(newSlice, 60) newSlice = append(newSlice, 50) source := []string{"Apple", "Orange", "Plum", "Banana", "Grape"} slice8 := source[2:3:4] for index, value := range source { fmt.Printf("Index: %d Value: %s\n", index, value) } for index :=2; index < len(source); index++ { fmt.Printf("Index: %d Value: %s\n", index, source[index]) } slice9 := [][]int{{10}, {100, 200}} slice9[0] = append(slice9[0], 20) fmt.Println(slice1, slice2, slice3, slice4, slice5, slice6, slice7, newSlice, slice8, slice9) }
相关文章推荐
- Go语言基础:array、slice、make和new操作、map
- go语言笔记——切片函数常见操作,增删改查和搜索、排序
- 【Go语言】基本类型排序和 slice 排序
- Go语言 --- slice切片
- Go语言学习笔记十一: 切片(slice)
- 关于go语言中的Slice切片问题
- Go语言中Slice(切片)初探
- Go语言map映射的基本操作
- Go语言Slice操作.
- go语言笔记——切片底层本质是共享数组内存!!!绝对不要用指针指向 slice切片本身已经是一个引用类型就是指针
- Go语言学习笔记 --- slice切片
- 十分钟讲明白, golang, Go 语言切片(Slice)
- Go语言中的数组(array)和数组切片(slice)
- 【Go学习】slice切片的本质及操作——切片的追加、删除、插入等
- Go 语言切片(Slice)
- Go语言Slice操作.
- 【Go入门教程4】变量(var),常量(const),内置基础类型(Boolean、数值 byte,int,rune、字符串、错误类型),分组,iota枚举,array(数值),slice(切片),map(字典),make/new操作,零值
- Go 语言切片(Slice)
- Go语言学习笔记十一: 切片(slice)
- go语言实现基本的栈操作