Arrays, slices, and maps
Arrays are one of the most widely used types of computer programming. They are lists of other types that you can access by using their position on the list. The only downside of an array is that its size cannot be modified. Slices allow the use of arrays with variable size. The maps
type will let us have a dictionary like structures in Go. Let's see how each work.
Arrays
An array is a numbered sequence of elements of a single type. You can store 100 different unsigned integers in a unique variable, three strings or 400 bool
values. Their size cannot be changed.
You must declare the length of the array on its creation as well as the type. You can also assign some value on creation. For example here you have 100 int
values all with 0
as value:
var arr [100]int
Or an array of size 3 with strings
already assigned:
arr := [3]string{"go", "is", "awesome"}
Here you have an array of 2 bool
values that we initialize later:
var arr [2]bool arr[0] = true arr...