Golang container/list.List.Remove() function example
package container/list
Remove removes element (e) from list if (e) is an element of the list. It returns the element value e.Value.
Golang container/list.List.Remove() function usage example
package main
import (
"container/list"
"fmt"
)
func main() {
alist := list.New()
alist.PushFront("a")
alist.PushFront("b")
alist.PushFront("c")
alist.PushFront("d")
fmt.Println("Elements in List : ")
for e := alist.Front(); e != nil; e = e.Next() {
fmt.Println(e.Value) // print out the elements
}
elementFromAList := alist.Front()
removed := alist.Remove(elementFromAList)
fmt.Printf("Removed element [ %s ] from list\n", removed)
fmt.Println("List After Removal : ")
for e := alist.Front(); e != nil; e = e.Next() {
fmt.Println(e.Value) // print out the elements
}
}
Output :
Elements in List :
d
c
b
a
Removed element [ d ] from list
List After Removal :
c
b
a
Reference :
Advertisement
Something interesting
Tutorials
+7.3k Golang : Not able to grep log.Println() output
+5.9k Golang : Generate multiplication table from an integer example
+5.7k Golang : ROT32768 (rotate by 0x80) UTF-8 strings example
+10.8k PHP : Convert(cast) bigInt to string
+32.2k Golang : Convert []string to []byte examples
+8.3k Useful methods to access blocked websites
+20.7k Android Studio : AlertDialog and EditText to get user string input example
+9.7k Golang : interface - when and where to use examples
+16.6k Golang : Delete files by extension
+5.1k Linux/Unix/MacOSX : Find out which application is listening to port 80 or use which IP version
+5.3k Golang : Get FX sentiment from website example
+6.3k Apt-get to install and uninstall Golang