0 votes
in GoLang by
What is the easiest way to check if a slice is empty?

1 Answer

0 votes
by

Create a program that checks if a slice is empty. Find the simplest solution.

Solution

The easiest way to check if a slice is empty is to use the built-in len() function, which returns the length of a slice. If len(slice) == 0, then you know the slice is empty.

For example:

package main

import "fmt"

func main() {

  r := [3]int{1, 2, 3}

  if len(r) == 0 {

    fmt.Println("Empty!")

    

...