Skip to content

Instantly share code, notes, and snippets.

@hygull
Last active February 1, 2017 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hygull/0f7d8e3981d7690fbb4fcfd96a2df6b8 to your computer and use it in GitHub Desktop.
Save hygull/0f7d8e3981d7690fbb4fcfd96a2df6b8 to your computer and use it in GitHub Desktop.
Checking availabillity of keys in map created by hygull - https://repl.it/Eifo/10
/*
@Date of creation : 24 November 2016.
@Aim of program : To check the availability status of keys in MAP.
@Go version : 1.7.1 [go version command(on MAC )prints -> go version go1.7.1 darwin/amd64]
@Coded by : Rishikesh Agrawani.
*/
package main
import "fmt"
func main() {
detailsMap := make(map[string]string) //Defining a map
detailsMap["name"] = "Rishikesh Agrawani" //Adding one key-value pair to map
detailsMap["branch"] = "CSE" //Adding another key-value pair to map
val, isKeyPresent := detailsMap["name"] //Getting the value of key 'name', that exists
fmt.Println(val, isKeyPresent) //Printing the fetched value and its availability information
val, isKeyPresent = detailsMap["branch"] //Getting the value of key 'branch', that exists
fmt.Println(val, isKeyPresent) //Printing the fetched value and its availability information
val, isKeyPresent = detailsMap["age"] //Getting the value of key 'age', that does not exist
fmt.Println(val, isKeyPresent) //Printing the fetched value and its availability information
}
/*COMMAND:-
go run map_key_availability_check.go
OUPUT:-
Rishikesh Agrawani true
CSE true
false
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment