Last Updated: May 22, 2026
Sorting shows up in almost every program that displays a list to a user or feeds data into another algorithm. The sort package, part of Go's standard library since version 1, provides a small set of generic-feeling tools to order slices of built-in types, slices of anything via a comparator function, and arbitrary collections that implement a three-method interface. It also includes a binary search routine for finding values in sorted data. This chapter covers each of those tools, when to use which, and the trade-offs (stability, transitivity, allocation) that decide whether your sort gives you the result you expected.