Home » Android » listview – Is there anything like NSDictionary in android?

listview – Is there anything like NSDictionary in android?

Posted by: admin June 15, 2020 Leave a comment


I’m new to Android. I did search around but couldn’t find anything work like NSdictionary of iOS in Android. For example in iOS I can create SIMPLE array of dictionary like this format

   idx1: [objA1 for keyA],[objB1 for keyB],[objB1 for keyC]
   idx2: [objA2 for keyA],[objB2 for keyB],[objB2 for keyC]
   idx3: [objA3 for keyA],[objB3 for keyB],[objB3 for keyC]

I know I can create string-array that work similar like that in android

<string-array name="list_obj1">
<string-array name="list_obj2">
<string-array name="list_obj3">

My question is if there is anything else used to create AN array of dictionary in Android like iOS.

Thank you for your help.

How to&Answers:

First, I think there are many tutorial about this stuff then you can search for more info.
Since you are new to android you might not know the “name” to search. For this case, “HashMap” is what you looking for. It works like NSdictionary.

//Create a HashMap
Map <String,String> map =  new HashMap<String,String>();
//Put data into the HashMap

// Now create an ArrayList of HashMaps
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();

//Add the HashMap to the ArrayList

Now you have st like an array of dictionary.

Hope this help.


You could put what @user1139699 said into an ArrayList.

ArrayList<HashMap> list = new ArrayList();

Map <String, String> map =  new HashMap<String,String>();



also if you want to load a file like this:

property.key.1=value of 1st key
property.key.2=value of 2nd key
prompt.alert = alert 

etc you may use java Properties(); Then you can instantly get the value of each key.


You have for example a file myTranslations.txt . In that file you write pairs of keys/values in the format:

property.key.1=value of 1st key
property.key.2=value of 2nd key
prompt.alert = alert 

where the part before the “=” is the key, and the part after is the value.

Then in your code you do:

Properties properties = new Properties();

    File propertiesFile = new File (filePath);
    FileInputStream inputStream = null;
    try {
        inputStream = new FileInputStream(propertiesFile);
    } catch (IOException ioe) {

where filePath is the path to file above.

Then you can get the value of each key as:


which will return the string:


as it is in the txt file.

If it helps please upvote.