logo-MindMajix
PostGoLangGoLang
i
imran mohammad

Posted on 26th July 2024|83 views

0
votes

Golang Compare Slices

How can I compare two slices of bytes in Golang?

1 answers
Answers
P
sumana reddy

Posted on 26th July 2024| views

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
Name
Course *
Email *
Phone Number