How to create Empty and Nil Slice?
The Sort function sorts the data interface in both ascending and descending order. IntSlice attaches the methods of Interface to []int, sorting in increasing order. StringSlice attaches the methods of Interface to []string, sorting in increasing order.
Below is an example to search particular string or integer in string or integer slice vice versa.
Example
package main
import (
"fmt"
)
func main() {
var nilSlice []string
var emptySlice = []string{}
fmt.Printf("\nNil:%v Len:%d Capacity:%d",nilSlice == nil, len(nilSlice), cap(nilSlice))
fmt.Printf("\nEmpty:%v Len:%d Capacity:%d",emptySlice == nil, len(emptySlice), cap(emptySlice))
}
Output
Nil:true Len:0 Capacity:0
Empty:false Len:0 Capacity:0
Most Helpful This Week
How can I convert a string variable into Boolean, Integer or Float type in Golang?
Generate a Keygen of 256 bits
Regular expression for matching HH:MM time format in Golang
How to read names of all files and folders in current directory?
How pointer & and * and ** works in Golang?
How to split a string on white-space?