Golang ProgramsGolang Programs

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.
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))
}
C:\golang\codes>go run example.go

Nil:true Len:0 Capacity:0
Empty:false Len:0 Capacity:0
C:\golang\codes>