当前位置:网站首页>go 切片,集合简单讲解
go 切片,集合简单讲解
2022-07-22 07:46:00 【码农竟在我身边】
go 切片,集合简单讲解
arr := []int{
1, 2, 3, 4, 5,
}
//添加
arr = append(arr, 0, 1)
//翻转
arr = reverse(arr)
//切片会自动取址 所以需要copy函数
arr2 := arr
arr[0] = 99
//example
//申明初始长度和最大容度 可以复制
arr3 := make([]int, 10, 10)
//普通申明的复制失败
var arr4 []int
copy(arr3, arr2)
copy(arr4, arr2)
arr[0] = 22
//var arr = make([]string, 1, 5)
fmt.Println(arr2, arr3, arr4)
for _, item := range arr2 {
fmt.Print(item)
}
fmt.Println()
//申明集合 建议是用Make
obj := make(map[string]string)
obj["name"] = "jump"
obj["sex"] = "boy"
for index, item := range obj {
fmt.Println(index, item)
}
//删除对应key
delete(obj, "sex")
for index, item := range obj {
fmt.Println(index, item)
}
//判断是否存在Key
v, ok := obj["sex"]
if ok {
fmt.Println(v)
} else {
fmt.Println(ok)
}
边栏推荐
- MySQL JDBC programming
- bokeh参数设置详解
- buu-misc进阶
- 【微服务~远程调用】整合RestTemplate、WebClient、Feign
- 所有navicat版本都支持MySQL吗,为什么我打开连接不上呢?
- 网络之数据链路层(PPP协议)
- Linear regression (formula derivation +numpy Implementation)
- Physical layer of network
- What is the difference between win11 beta 22621.436 and 22622.436?
- 【HMS core】【FAQ】【Account Kit】典型问题集2
猜你喜欢
从0开始教你编写Makefile文件
Data Lake (18): Flink and iceberg integrate SQL API operations
[HMS core] [Health Kit] [FAQ] collection of data subscription function questions
数据湖(十八):Flink与Iceberg整合SQL API操作
Branch and loop statements
日期类的理解学习
MySQL 增删改查(进阶)
继承的详解
异常的理解学习
[FPGA tutorial case 35] communication case 5 - 16QAM modulation signal generation based on FPGA, and its constellation is tested by MATLAB
随机推荐
使用 Abp.Zero 搭建第三方登录模块(四):微信小程序开发
MySQL constraints
Architecture (I) what is architecture
C static classes and static class members
MySQL 增删改查(进阶)
PostgreSQL database is deployed on Linux server. Ms level is queried locally. Pgadmin installed on windows is used to query super slow for about 20s. Is it a network problem or a database configuratio
日期类的理解学习
Teach you to write makefile files from 0
微信小程序学习五种页面跳转方法
Virtual machine performance test scheme
Can the task of flinksql monitor whether it is interrupted?
Real time synchronization and conversion of massive data based on Flink CDC
MySQL series article 4: execution plan
How is VR panorama displayed in all walks of life? How to implement the application?
[HMS core] [FAQ] [account kit] typical problem set 2
数据湖(十八):Flink与Iceberg整合SQL API操作
Prepare for the attack and defense drill. Here is a security deployment map of Tencent!
MySQL约束
Detailed explanation of inheritance
Install vscode offline