Standard library / sort

sort.StringSlice.Swap()

Exchanges elements at two valid indices in the receiver; invalid indices panic. Expected stdout: '[b a c]\n'.

Formal Syntax & Structure

go syntaxgo
func (x StringSlice) Swap(i, j int)

Parameters & Attributes

NameTypeDescription
iintIndex or start position.
jintSecond index or exclusive end position.

Working Example

Example Snippetgo
package main
import (  "fmt"  "sort")
func main() {  a := sort.StringSlice([]string{"a", "b", "c"})  a.Swap(0, 1)  fmt.Println(a)}
Go Reference