Udemy
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
Turn what you know into an opportunity and reach millions around the world.
Learn More
Your cart is empty.
Keep shopping
Succinct Go Language Tutorial: Arrays & Slices (BOOK 2)
Rating: 4.8 out of 5(69 ratings)
1,590 students

Succinct Go Language Tutorial: Arrays & Slices (BOOK 2)

Learn, Practice, Review - Your second volume in your Go basic syntax adventure. Go 1.24 tested.
Created byTony de Araujo
Last updated 2/2025
English

What you'll learn

  • Beginners with some exposure to basic Go, but the course is self-contained.
  • Intermediate Go programmers who want to review and expand their knowledge of arrays and slices.
  • Advanced programmers in other languages wanting to explore the Go language.
  • All exercises are shown in the Golang playground. You just need access to the Internet.
  • GO arrays and slice techniques explained in detail as well as Go for/range loops.
  • Start learning GO data structures here with arrays and slice exercises. Coding is easy if properly taught.
  • This is the second volume in the series. Begin with Volume One if you are new to Golang.

Course content

1 section49 lectures1h 46m total length
  • Why arrays?1:18

    Hello and welcome to another volume in this course series. Now that we know about Go variables, loops, conditional statements, and basic functions from volume 1 (or equivalent), it is time to study arrays, slices, maps, and structs. And we start with arrays because they are the foundation for everything else.

  • What are arrays in Go?2:55
  • Array declaration using default values4:17

    How to declare arrays in Go using default values.  How to reassign values to array indexes.

  • Declaring and assigning. Length of an array5:25

    How to assign values when declaring an array in Go. How to calculate the length of an array. How to find the last index number of an array.

  • Overriding index numbers when declaring arrays1:35

    How to override default index numbers when declaring an array in Go.

  • The for loop in Go4:03

    Three ways to use a for loop. How to traverse arrays using a for loop.

  • The range loop in Go1:30

    How to use the range keyword in a for loop to traverse an array in Go.

  • Good news on For Range loops0:17

    As of Go 1.22, we can now use the for range loop for integers (in addition to arrays and slices)

  • Exercise - Print odd numbers from array values0:24

    In this exercise you will practice declaring an array and looping over that array with a for range loop construct. You will also review conditional statements and the modulus operator.

  • Solution - Print odd numbers from array values1:35

    Demonstration on how to do the previous exercise. How to print odd numbers from an array using the for range loop and the modulus operator. Downloadable file is available.

  • Data in arrays is passed by value2:06

    In this video you will see that data in arrays is normally passed by value.  Sample coder is available for download.

  • Passing arrays by reference6:30

    Passing array references. Introducing the pointer array data type.

  • Passing a subset range of an array in Go3:50

    How to use the range concept to pass part of an array to another variable.

  • Array slices are pointers to array values6:02

    In this exercise you will see how values in a slice point to values in an underlying array. You will also review how to check the data type of an array using the typeOf function from the reflect package.

  • What is a slice?3:43

    Introducing the concept of slices, as well as the definition of capacity and length.

  • Three ways to declare a slice6:12

    How to declare a slice in Go. An explanation of the three declaration styles, some advantages and disadvantages.

  • Appending new items to a Go slice4:39

    How to append one or more values to an existing slice.

  • Optional quiz to check your understanding so far
  • In Go, strings are line slices, but with a fixed length5:25

    A string is a slice of bytes. In this exercise we will investigate the difference between fetching a range of characters from a string value and fetching a single character from it.

  • Appending a slice to another slice using the ellipsis (...) operator | also Copy3:32

    How to append a slice to an existing slice.

  • Appending a limited slice range of values to another slice2:25

    How to append a range of values from a slice to another slice.

  • Adding values to an empty slice2:26

    How to add new values to an empty slice. Two ways of declaring an empty slice in Go.

  • Optional exercise – a slice of bytes0:27

    This is an extra practicing exercise. Here you will use the make function to create a slice of bytes and then use the string function to convert bytes into the letters of a single word.

  • Solution – slice of bytes0:24
  • Copying slices using the copy() function4:30

    How to copy slices or part of slices using the copy function.

  • Optional exercise – Copying a slice of integers0:50

    This exercise demonstrates how  the copy function copies values to similar index numbers on the target slice. If the target slice is larger than the source, the remaining indexes will keep their default values. This is a preparation for the next exercise where we will see how to copy values to specific locations.

  • Copying slices to specific target indexes3:28

    How to copy a slice into a specific range of index on another slice.

  • Optional exercise on copying slices0:27
  • Slice copying exercise demo2:39

    This video is a demonstration of the previous exercise. Copying a slice of ints into a new slice.

  • Deleting an item from a slice using append()3:55

    How to delete an element from a slice using the append function.

  • Optional exercise: Deleting two items from a slice using append()0:07

    This is the same exercise as the previous video, but it deletes two items instead of just one.

  • Exercise result: Deleting two items from a slice using append()0:20
  • How to extend a slice using append and make2:31

    How to include make as a second argument of an append function.

  • Inserting a new item in the middle of a slice using 2 append()s3:59

    How to insert a new item in a Go slice in any index position.

  • Optional exercise: Append two items to the middle of a slice using two append()s0:09

    This is a practicing exercise. It should help cement concepts.

  • Answer: Append two items to the middle of a slice0:06

    Solution on how to append two items to the middle of a slice in Go.

  • Optional exercise: Append three items to the end of a slice0:11

    This is a practicing exercise. It should help cement concepts.

  • Answer: Append three items to the end of a slice0:21

    Solution on how to append three items to the end of a Go slice.

  • Optional exercise: Append an existing slice to the middle of another slice0:14

    This is a practicing exercise. It should help cement concepts.

  • Answer: Append an existing slice to the middle of another slice0:09

    Solution on how to append an existing slice to the middle of another slice in Go.

  • Optional exercise: Append an existing slice to the middle of a modified slice0:17

    This is a practicing exercise. It should help cement concepts.

  • Answer: Append an existing slice to the middle of a modified slice0:22

    Solution on how to append an existing slice to the middle of another slice in Go and delete the last item in the process.

  • Lecture: Appending data into mixed indexes4:38

    Sometimes it is best to append to a temporary slice before making the final assignment. This is particular true if we are appending to mixed index positions.

  • Optional exercise: Append cardinal numbers in the proper order0:15

    This exercise is a review of the previous video.

  • Answer: Append cardinal numbers in the proper order0:20

    Solution on how to append a slice to another by targeting non consecutive indexes.

  • Optional exercise: Appending three slices to a new slice0:15

    In this exercise try appending three slices into a fourth one.

  • Answer: Appending three slices0:26

    Solution on how to append three slices into a fourth one.

  • Lecture: Two-dimensional arrays3:46

    Introduction to multidimensional arrays in Go.

  • RESOURCES: Go Arrays and Slices0:19
  • Thank you0:44

    Thank you dear friend. I will see you soon.

Requirements

  • This is an intermediate Go study course. Prior exposure to variables and basic functions is helpful.
  • This is the second volume of a series but it is self-contained.
  • The project is designed for both learning or reviewing. Videos are self-contained.

Description

This is the second volume of the GO Language series  by Tony de Araujo. It contains around two hours of videos and exercises designed to make you proficient on Go array and slice structures.

Rather than being a primer, it is a didactic sequential approach with short explanations and exercises. By the end of this tutorial series, you’ll have a solid understanding of arrays and slices in Go, enabling you to choose the right data structure for your specific use case.

Understanding Arrays and Slices in Go

In Go, arrays and slices are essential data structures that allow you to work with ordered sequences of elements.
These collections are particularly useful when dealing with related values.

Here’s a breakdown of the key differences between arrays and slices:


Arrays:

  • In Go an array is a fixed-size data structure.

  • Its capacity is defined at creation time and cannot be changed afterward.

  • Once you allocate an array’s size, it remains constant.

  • Arrays are suitable when you know the exact number of elements you need.\Example: var myArray [5]int creates an integer array with 5 elements.

Slices:

  • A slice is a dynamically resizable data structure.

  • Unlike arrays, slices can grow or shrink as needed.

  • Slices are built on top of arrays and provide a more flexible way to work with sequences.

  • They are commonly used when the number of elements is not fixed.

  • Example: mySlice := []int{1, 2, 3} creates an integer slice.


Why Use Arrays and Slices?

  • Data Organization: Arrays and slices allow you to group related data together. For instance, you can store a list of temperatures, user IDs, or product prices.

  • Code Efficiency: By using arrays and slices, you can perform the same operations on multiple values simultaneously. This leads to cleaner and more concise code.

  • Flexibility: Slices adapt to your needs, making them ideal for scenarios where the size may change dynamically.


Tutorial Series Contents:

1. Introduction: Understand the basics of arrays and slices.

2. Declaration and Initialization: Learn how to declare and initialize arrays and slices.

3. Accessing Elements: Explore methods to access individual elements.

4. Modifying Elements: Discover how to modify array and slice elements.

5. Iterating Over Arrays and Slices: Master loops and range-based iteration.

6. Multidimensional Arrays: Dive into arrays with multiple dimensions.

7. Built-in Functions: Explore useful functions for working with arrays and slices.

By the end of this tutorial, you’ll have a solid understanding of arrays and slices in Go, enabling you to move forward into other data structures on subsequent volumes.


Who this course is for:

  • Go language students wanting to understand arrays and slices
  • Go programmers who want to refresh syntax and concepts