package main
import "github.com/sanity-io/litter"
// slice增删改查,很实用
func main() {
var sliceInt []int
// init
sliceInt = append(sliceInt, []int{1, 2, 3, 4}...)
litter.Dump(sliceInt)
// remove index 0
sliceInt = append(sliceInt[:0], sliceInt[1:]...)
litter.Dump(sliceInt)
sliceInt = append(sliceInt, []int{5,6,7,8,9,10}...)
litter.Dump(sliceInt)
// remove elem when iterator
for i:= len(sliceInt)-1; i >=0; i-- {
if sliceInt[i] % 2 == 0 {
sliceInt = append(sliceInt[:i], sliceInt[i+1:]...)
}
}
litter.Dump(sliceInt)
// update elem
sliceInt[len(sliceInt)-1] = 10
litter.Dump(sliceInt)
}
output
[]int{
1,
2,
3,
4,
}
[]int{
2,
3,
4,
}
[]int{
2,
3,
4,
5,
6,
7,
8,
9,
10,
}
[]int{
3,
5,
7,
9,
}
[]int{
3,
5,
7,
10,
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- 数据结构 – 用于构建文件系统的数据结构?
- 荐 用Python解决数据结构与算法问题(三):线性数据结构之栈
- 数据结构和算法面试题系列-C指针、数组和结构体
- 请问二叉树等数据结构的物理存储结构是怎样的?
- 数据结构——单链表
- 常用数据结构
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Agile Web Development with Rails 4
Sam Ruby、Dave Thomas、David Heinemeier Hansson / Pragmatic Bookshelf / 2013-10-11 / USD 43.95
Ruby on Rails helps you produce high-quality, beautiful-looking web applications quickly. You concentrate on creating the application, and Rails takes care of the details. Tens of thousands of deve......一起来看看 《Agile Web Development with Rails 4》 这本书的介绍吧!
RGB转16进制工具
RGB HEX 互转工具
XML 在线格式化
在线 XML 格式化压缩工具