How to sort a slice of string values in Go

1 Answer

0 votes
package main 
  
import ( 
    "fmt"
    "sort"
) 
  
func main() { 
    slice := []string{"go", "c", "php", "c++", "python", "java"} 

    fmt.Println(slice) 
  
    sort.Strings(slice) 

    fmt.Println(slice) 
} 
 

  
/*
run:
   
[go c php c++ python java]
[c c++ go java php python]

*/

 



answered Aug 17, 2020 by avibootz
...