Go map type

Source: Internet
Author: User
This is a created article in which the information may have evolved or changed.
map structure, personal feel can and PHP is a kind of array, is a key-value hash structure. In go, key can be a type other than the Func,array,slice,map type

Simple to use:

 m:=map[string]string{} m["key1"]="val1"

The map structure and slice are the same, and are a pointer. When assigning a value, copy the pointer to the new variable

Map additions and deletions to check the operation:

package  mainimport "fmt"func main(){   m:=map[string]string{"key1":"value"}   fmt.Println(m)   m["key2"]="value2"   fmt.Println(m)   p:=m["key1"]   fmt.Println(p)   delete(m,"key1")   fmt.Println(m)}

New and make differences

New (T) can be used to create a normal type, returning a pointer to the initialized T value.
Make (S) can only be used to create slice,map,channel. Returns an initialized s value (equivalent to a pointer).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.