Standard library / sync

sync.Map.Load()

Read a value and distinguish a missing key from a stored nil. Expected stdout: '1 true\n'.

Formal Syntax & Structure

go syntaxgo
func (m *Map) Load(key any) (value any, ok bool)

Parameters & Attributes

NameTypeDescription
keyanyComparable map key, or a package-specific comparable context key.

Return Value

(value any, ok bool)

Stored value and presence flag.

Working Example

Example Snippetgo
package main
import (  "fmt"  "sync")
func main() { var m sync.Map; m.Store("a", 1); v, ok := m.Load("a"); fmt.Println(v, ok) }
Go Reference