Menu Close

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

In this tutorial, we are going to learn about Back() function in list package in go golang. Back() function is used to get the last element of list in go golang.

Function proto type:

 func (l *List) Back() *Element 

Back() function:

Back() function returns the last element of list or nil if the list is empty. 

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

Example to use Back() function in list:

package main

import (

func main() {
  // Create a new list and insert elements in it.
  l := list.New()
  l.PushBack(1)  // 1
  l.PushBack(2)  // 1 -> 2
  l.PushBack(3) // 1 -> 2 -> 3

  // get the head of the list
  ele := l.Back()




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 *