Home >Backend Development >Golang >Is map in golang a structure?
#map in golang is not a structure.
Map is an unordered collection of key-value pairs. The most important point of Map is to quickly retrieve data through key. Key is similar to an index and points to the value of the data.
Map is a collection, so we can iterate over it just like arrays and slices. However, Map is unordered and we cannot determine the order in which it is returned. This is because Map is implemented using a hash table.
Define Map
You can use the built-in function make or you can use the map keyword to define Map:
/* 声明变量,默认 map 是 nil */ var map_variable map[key_data_type]value_data_type /* 使用 make 函数 */ map_variable := make(map[key_data_type]value_data_type)
Go languageArrays can store the same type of data, but in structures we can define different data types for different items.
A structure is a data collection composed of a series of data of the same type or different types.
Define structure
Structure definition requires the use of type and struct statements. The struct statement defines a new data type, with one or more members in the structure. The type statement sets the name of the structure. The format of the structure is as follows:
type struct_variable_type struct { member definition member definition ... member definition }
For more golang knowledge, please pay attention to the golang tutorial column.
The above is the detailed content of Is map in golang a structure?. For more information, please follow other related articles on the PHP Chinese website!