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
| Name | Type | Description |
|---|---|---|
| i | int | Index or start position. |
| j | int | Second 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)}