Go TutorialLesson 11Free preview
Go Slices
This lesson is part of Go · All levels
Summary
This lesson explains slice, data structure that contains a set of elements with dynamic lengths that are favorites in Go. Slice can be made directly with []type or via make(), and can be grown using append(). Internally the slice is a pointer to the array, length (len), and capacity (cap), so that the change in the element affects the underlying array.
Key points
- Slice made with []type{} or make([]tipe, panjang, kapasitas)
- Append() adds elements and copies to the new array when full capacity
- Len() and cap() each return the length and capacity of the slice
- Slice is a reference type; changes in the element are visible on the same base array
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.