Posts

Showing posts with the label Reverse

Sort a String Array/Slice in Go Language

Image
Hello everyone, In this tutorial, we will show you how to  Sort a String Array/Slice Alphabetically in Go Language. Example 1:  Sort a String Slice Alphabetically // Golang program to demonstrate the // example of sort.Strings() Method package main import ( "fmt" "sort" ) func main() { strarray := [] string { "Zeebra" , "Lion" , "Ant" , "Tiger" , "Hen" , "Snake" } fmt.Println( "Before Sort:" , strarray) sort.Strings(strarray) fmt.Println( "After Sort:" , strarray) } Output: Example 2:  Sort a String Array Alphabetically // Sort a String Array Alphabetically package main import ( "fmt" "strings" ) func main() { strarray := [ 6 ] string { "Zeebra" , "Lion" , "Ant" , "Tiger" , "Hen" , "Snake" } fmt.Println( "Before Sort:" , s