One - One Code All

Blog Content

Go语言列表list长度

Go   2018-09-09 15:00:13

Golang 的 列表 长度的获取使用列表内置的 Len 函数。

package main
import (
	"container/list"
	"fmt"
)
func main() {
	
	//使用列表内置的 Len() 函数,获取列表的长度
	listHaiCoder := list.New()
	listHaiCoder.PushFront("Hello")
	listHaiCoder.PushFront("HaiCoder")
	listHaiCoder.PushFront("嗨客网")
	len := listHaiCoder.Len()
	fmt.Println("Len =", len)
}

我们通过 list.New 创建了一个列表 listHaiCoder,接着使用 PushFront 函数在列表的头部连续插入了三个元素。最后,我们使用列表内置的 Len 函数,获取列表的长度。



上一篇:linux shell 中判断文件、目录是否存在的方法
下一篇:mac退格键

The minute you think of giving up, think of the reason why you held on so long.