How to determine whether map exists in golang

Release: 2019-12-24 11:22:49
Original
10868 people have browsed it

How to determine whether map exists in golang

Map is an unordered collection of key-value pairs. The most important point of Map is to quickly retrieve data through key, which is similar to an index and points to the value of the data.

Map is a collection, so we can iterate over it just like arrays and slices. However, Map is unordered and we cannot determine the order in which it is returned. This is because Map is implemented using a hash table.

Golang determines whether the map exists:

   if v, ok := m1["a"]; ok {
        fmt.Println(v)
    } else {
        fmt.Println("Key Not Found")
    }
Copy after login

If ok is true, it means the map exists, and if ok is false, the map does not exist.

For more golang knowledge, please pay attention to the golang tutorial column on the PHP Chinese website.

The above is the detailed content of How to determine whether map exists in golang. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!