Last active
February 1, 2017 17:14
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
@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