Post

GoLangGoLang

i
imran mohammad

Posted on 24th April 2024|82 views

0
votes

Golang Compare Slices

How can I compare two slices of bytes in Golang?

Answers
P
sumana reddy

Posted on 24th April 2024

You can use compare() function to compare two slices in Golang here the example 

package main

  import (

    "bytes"

    "fmt"

)

  func main() {

    1slice := []byte{'M', 'I', 'N', 'D'}

    2slice := []byte{'M', 'E', 'N', 'D'}

      res := bytes.Compare(1slice, 2slice)

   if res == 0 {

        fmt.Println("both the slices are equal")

    } else {

        fmt.Println("both the slices are not equal")

    }

}

Output:

both the slices are not equal

 

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo
  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos