The type [n]T
is an array of n
values of type T
.
Init with array literal:
Init specifying indexes:
Init without specifying the size:
An arrayβs length is part of its type, so arrays cannot be resized.
Array literal:
Arrays are too rigid to use directly, and slices are more common.
To simulate multidimensional arrays:
This declares x to be an array of length 2 whose type is an array of ints of length 3. This sounds pedantic, but some languages have true matrix support, like Fortran or Julia; Go isnβt one of them.
You canβt use a type conversion to directly convert arrays of different sizes to identical types.
Convert to slice
Take a slice from an array with a slice expression [:]
:
To convert a subset of an array:
Be aware that the memory will be shared, and changes to a slice will be visible on the array as well.
Copy
copy()
can be used, same as with slices.