创建:

arr1 := new([len]type)

slice1 := make([]type, len)

初始化:

arr1 := […]type{i1, i2, i3, i4, i5}

arrKeyValue := [len]type{i1: val1, i2: val2}

var slice1 []type = arr1[start:end]

(1)如何截断数组或者切片的最后一个元素:

line = line[:len(line)-1]

(2)如何使用for或者for-range遍历一个数组(或者切片):

  1. for i:=0; i < len(arr); i++ {
  2. = arr[i]
  3. }
  4. for ix, value := range arr {
  5. }

(3)如何在一个二维数组或者切片arr2Dim中查找一个指定值V:

  1. found := false
  2. Found: for row := range arr2Dim {
  3. for column := range arr2Dim[row] {
  4. if arr2Dim[row][column] == V{
  5. found = true
  6. break Found
  7. }
  8. }
  9. }