Skip to content

Commit f2b7634

Browse files
committed
Adds slicing slices eg
1 parent f056f59 commit f2b7634

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

codes/ch6_slices/slicing-slices.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func main() {
6+
7+
/**
8+
* Blank [] will declare a slices.
9+
* If you provide size like [5] will declare an array.
10+
*/
11+
var employee []string
12+
13+
/**
14+
* Initialize a slices with type, length and capacity.
15+
* length is required field.
16+
*
17+
* make([]string, length, [capacity])
18+
*/
19+
employee = make([]string, 7)
20+
21+
employee[0] = "Ashwin"
22+
employee[1] = "Kumar"
23+
employee[2] = "Saju"
24+
employee[3] = "Ajay"
25+
employee[4] = "Jerin"
26+
employee[5] = "Vinayak"
27+
employee[6] = "Pavan"
28+
29+
/**
30+
* Slices and updating slices
31+
*/
32+
employee = employee[0:]
33+
fmt.Println("[0:]", employee)
34+
35+
employee = employee[0:7]
36+
fmt.Println("[0:7]", employee)
37+
38+
employee = employee[0:len(employee)]
39+
fmt.Println("[0:len(employee)]", employee)
40+
41+
employee = employee[:4]
42+
fmt.Println("[0:4]", employee)
43+
44+
employee = employee[0:4]
45+
fmt.Println("[:4]", employee)
46+
47+
employee = employee[4:7]
48+
fmt.Println("[4:7]", employee)
49+
}

0 commit comments

Comments
 (0)