Standard library / bytes
bytes.Compare()
Compares inputs lexicographically by bytes, returning -1, 0 or 1. Use bytes.Equal for equality; nil and empty slices compare equal. Expected stdout: '-1\n'.
Formal Syntax & Structure
go syntaxgo
func Compare(a, b []byte) intParameters & Attributes
| Name | Type | Description |
|---|---|---|
| a | []byte | First input to compare. |
| b | []byte | Second input to compare. |
Return Value
int
Compares inputs lexicographically by bytes, returning -1, 0 or 1. Use bytes.Equal for equality; nil and empty slices compare equal.
Working Example
Example Snippetgo
package main
import ( "bytes" "fmt")
func main() { fmt.Println(bytes.Compare([]byte("a"), []byte("b")))}