To create a HashMap in android and get values from it.
Use the following code to initialize your Map
HashMap<String, String> countryLookupMap=new HashMap<String, String>();
countryLookupMap.put("AD","Andorra");
countryLookupMap.put("AE","United Arab Emirates");
countryLookupMap.put("AF","Afghanistan");
countryLookupMap.put("AG","Antigua and Barbuda");
countryLookupMap.put("AI","Anguilla");
countryLookupMap.put("AL","Albania");
countryLookupMap.put("AM","Armenia");
<<
To retrieve the values from your HashMap
>>
String key;
String name = (String) countryLookupMap.get(key);
if (name != null) {
String country = name;
}
else
{
// Value to the given key i not preasent
}
<<
No comments:
Post a Comment