In this tutorial, we are going to learn about Init() function in list package in go golang. Init() function is used to initialize or clear list in go golang.
Function proto type:
func (l *List) Init() *List
Init() function:
Init initializes or clears list.
Example to use Init() function in list:
package main
import (
"container/list"
"fmt"
)
func main() {
// Create a new list and insert elements in it.
l := list.New()
l.PushBack(1)
l.PushBack(2)
l.PushBack(3)
// Print length of list
fmt.Println("Len is", l.Len())
l.Init()
fmt.Println("Len after applying Init function: ", l.Len())
}
Output:
Len is 3
Len after applying Init function: 0
To learn more about golang, Please refer given below link:
https://www.techieindoor.com/go-lang-tutorial/
References:
https://golang.org/doc/
https://golang.org/pkg/
https://golang.org/pkg/fmt/
https://golang.org/pkg/fmt/#Println
https://golang.org/pkg/container/list/