Menu Close

Go – Init() function in list package in go golang

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.

To learn more about list package in go, Please follow this link

Example to use Init() function in list:

package main

import (

func main() {
  // Create a new list and insert elements in it.
  l := list.New()

  // Print length of list
  fmt.Println("Len is", l.Len())

  fmt.Println("Len after applying Init function: ", l.Len())


 Len is 3
Len after applying Init function:  0

To learn more about golang, Please refer given below link:

Posted in golang, list package

Leave a Reply

Your email address will not be published. Required fields are marked *