Standard library / sort

sort.StringSlice.Less()

Reports whether the element at i precedes the element at j. Indices must be valid. Expected stdout: 'true false\n'.

Formal Syntax & Structure

go syntaxgo
func (x StringSlice) Less(i, j int) bool

Parameters & Attributes

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

Return Value

bool

Reports whether the element at i precedes the element at j. Indices must be valid.

Working Example

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