Go Maps: Difference between revisions
Jump to navigation
Jump to search
Line 14: | Line 14: | ||
=Declaration and Initialization= | =Declaration and Initialization= | ||
==Initialization with <tt>make()</tt>== | ==Initialization with <tt>make()</tt>== | ||
==Initialization with Composite Literal== | ==<span id='Composite_Literal'></span>Initialization with a Composite Literal== | ||
Composite literals can be used for map initialization. | |||
[[Go_Variables#Variable_Initialization_with_Type_Inference_in_Long_Declaration|Long variable declaration and initialization with type inference]]: | |||
<syntaxhighlight lang='go'> | |||
var mm = map[string]int {"A:1, "B":2} | |||
</syntaxhighlight> | |||
[[Go_Variables#Short_Variable_Declaration|Short variable declaration]]: | |||
<syntaxhighlight lang='go'> | |||
mm := map[string]int {"A:1, "B":2} | |||
</syntaxhighlight> | |||
=Operators= | =Operators= | ||
==Indexing Operator <tt>[]</tt>== | ==Indexing Operator <tt>[]</tt>== |
Revision as of 23:33, 26 August 2024
External
Internal
Overview
Maps and Pass-by-Value
Pointers to Maps
nil and Empty Map
nil Map
Empty Map
Declaration and Initialization
Initialization with make()
Initialization with a Composite Literal
Composite literals can be used for map initialization. Long variable declaration and initialization with type inference:
var mm = map[string]int {"A:1, "B":2}
mm := map[string]int {"A:1, "B":2}