From the course: Advanced Go Programming: Data Structures, Code Architecture, and Testing

Unlock the full course today

Join today to access over 24,900 courses taught by industry experts.

Go data structures

Go data structures

- [Instructor] Many programming languages such as Java and C# have implementations of the common data structures we have seen. Go has only a handful. Remember, we established that slices are flexible abstractions on top of arrays. They can be initialized using square brackets followed by the initial elements in curly braces. Elements can be accessed by index or using a loop with a range operator. The append function adds a new element to the end of the slice and handles all array growing and element copying under the hood. The len function returns the number of elements stored in the slice while the cap function returns the capacity of the underlying array. One thing that's important to remember when working with slices is that they contain references to data, not data itself. Let's have a look at an example. We begin by creating an int array containing the integers 10 to six. Then we create two slices, one with the…

Contents