In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
The knowledge points of this article "how to use go language to achieve array comparison" are not quite understood by most people, so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to use go language to achieve array comparison" article.
Compare whether two arrays are equal
If the two arrays are of the same type (including the length of the array and the type of the elements in the array), we can directly judge whether the two arrays are equal by comparing the operators (= = and! =). Only when all the elements of the two arrays are equal, the array is equal, can not compare two different types of arrays, otherwise the program will not be able to complete compilation.
Package mainimport ("fmt") func main () {/ / compare the array arr1: = [3] string {"Hello", "", "PHP"} arr2: = [3] string {"Hello", "PHP"} fmt.Println ("arr1 = = arr2", arr1 = = arr2)}
Output:
Arr1 = = arr2 true
Two arrays containing three elements are defined, and the elements of the array are the same. Then, we compare the two arrays with = =, and the result returns true, that is, the two arrays are equal.
Comparison of different array lengths
The length of the array is different, so you can't compare the array by = and!
Package mainimport ("fmt") func main () {/ / the array length is different, so you cannot compare the array arr1: = [3] string {"Hello", "", "hi"} arr2: = [2] string {"Hello", ""} fmt.Println ("arr1 = = arr2", arr1 = = arr2)}
After the program runs, the console output is as follows:
# command-line-arguments./main.go:9:35: invalid operation: arr1 = = arr2 (mismatched types [3] string and [2] string) the above article is about "how to use go language to achieve array comparison". I believe you all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to learn more about it, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.