Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check if the map has a specific string in it's keys, then give me it's value, that belong this key, Dart

may i ask how to check if the map of String,String has in it's keys a specific String then i want to get the value that belong this specific key that contains the target String. for example this Map

Map<String, String> ListFinalAllInfos = {'stackoverflow': 'one', 'google': 'two'};

and i want to check if this map has this String in it's keys

stackoverflow

if stackoverflow exists as a key inside the map then i want to get the value which is

one

without converting the map to a list, if this possible. thanks in advance

like image 370
test firma Avatar asked Sep 12 '25 04:09

test firma


1 Answers

Map<String, String> ListFinalAllInfos = {'stackoverflow': 'one', 'google': 'two'};
String key = ListFinalAllInfos.containsKey("stackoverflow"); // search for the key. for example stackoverflow
String value = ListFinalAllInfos[key]; // get the value for the key, value will be 'one'
if(ListFinalAllInfos.containsKey(value)){ //check if there is a key which is the value you grabbed
  return true;
}
like image 78
man of knowledge Avatar answered Sep 14 '25 17:09

man of knowledge