-
Notifications
You must be signed in to change notification settings - Fork 92
/
slice.go
61 lines (47 loc) · 1011 Bytes
/
slice.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import "fmt"
func main() {
var months = [...]string{
"Januari",
"Februari",
"Maret",
"April",
"Mei",
"Juni",
"Juli",
"Agustus",
"September",
"Oktober",
"November",
"Desember",
}
var slice1 = months[4:7]
fmt.Println(slice1)
fmt.Println(len(slice1))
fmt.Println(cap(slice1))
//months[5] = "Diubah"
//fmt.Println(slice1)
//slice1[0] = "Mei Lagi"
//fmt.Println(months)
var slice2 = months[11:]
fmt.Println(slice2)
var slice3 = append(slice2, "Eko")
fmt.Println(slice3)
slice3[1] = "Bukan Desember"
fmt.Println(slice3)
fmt.Println(slice2)
fmt.Println(months)
newSlice := make([]string, 2, 5)
newSlice[0] = "Eko"
newSlice[1] = "Kurniawan"
fmt.Println(newSlice)
fmt.Println(len(newSlice))
fmt.Println(cap(newSlice))
copySlice := make([]string, len(newSlice), cap(newSlice))
copy(copySlice, newSlice)
fmt.Println(copySlice)
iniArray := [5]int{1, 2, 3, 4, 5}
iniSlice := []int{1, 2, 3, 4, 5}
fmt.Println(iniArray)
fmt.Println(iniSlice)
}