go-slices


tags:

  • ready
  • online
  • reviewed
  • go
  • summary
  • informatic
  • data-structure
  • data-representation

slices

Contents

__Roadmap info from [ roadmap website ] (https://roadmap.sh/golang/go-basics/slices) __

Slices

Slices are similar to arrays but are more powerful and flexible.Like arrays, slices are also used to store multiple values of the same type in a single variable. However, unlike arrays, the length of a slice can grow and shrink as you see fit.

Array vs Slice

Slices:

  • Slices are similar to arrays, but are more powerful and flexible.
  • Like arrays, slices are also used to store multiple values of the same type in a single variable.
  • However, unlike arrays, the length of a slice can grow and shrink as you see fit.

Capacity vs length

  • len() function - returns the length of the slice (the number of elements in the slice)
  • cap() function - returns the capacity of the slice (the number of elements the slice can grow or shrink to)