Lesson

Sort Primitives (strings, ints, and floats) in Go

There are numerous ways to sort slices in Go.

Duration
4 min
Access
Free
Transcript
Available

There are numerous ways to sort slices in Go.

The simplest way uses some basic built-in functions from Go's sort package to allow you to easily sort slices of primitives, that being Strings, Ints and Float64s. Using these sort functions, we don't have control over the sort order as the data will be sorted in ascending alphabetical (for strings) or ascending numerical (for Ints and Float64s) order.

In this lesson, we will take a quick look at the easiest way to sort slices of primitives. We will learn about using some of the handy built-in functions in Go's sort package, including:

  • sort.Strings: Sorting a slice of strings
  • sort.Ints: Sorting a slice of ints
  • sort.Float64s: Sorting a slice of float64s