5

[Golang] Sort Words Alphabetically

 2 years ago
source link: http://siongui.github.io/2018/04/10/go-sort-words-alphabetically/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

[Golang] Sort Words Alphabetically

April 10, 2018

Go standard library provides sort.Strings to help us sort words alphabetically. The following example comes from Go official site.

Run Code on Go Playground

package main

import (
      "fmt"
      "sort"
)

func main() {
      s := []string{"Go", "Bravo", "Gopher", "Alpha", "Grin", "Delta"}
      sort.Strings(s)
      fmt.Println(s)
}

References:

[2][Golang] Sort String by Character


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK