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
Regular expression to extract text between square brackets
Example: Stack and Caller from RUNTIME package
How to check string contains uppercase lowercase character in Golang?
How to Draw a rectangle in Golang?
Add N number of Year, Month, Day, Hour, Minute, Second, Millisecond, Microsecond and Nanosecond to current date-time
What is Rune? How to get ASCII value of any character in Go?