Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Dictionary (like iphone NSDictionary) in android?

I have worked in soap message, and to parse the value from Webservice, the values are stored in ArrayList.

Example: values are Employee name (Siva) and Employee id (3433fd), these two values are stored in arraylist, but I want to stored in Dictionary, How?

like image 473
Sampath Kumar Avatar asked Jan 14 '12 08:01

Sampath Kumar


People also ask

What is the difference between NSDictionary and NSMutableDictionary?

Main Difference is:NSMutableDictionary is derived from NSDictionary, it has all the methods of NSDictionary. NSMutableDictionary is mutable( can be modified) but NSDictionary is immutable (can not be modified).

Do we have Dictionary in Java?

In Java, Dictionary is the list of key-value pairs. We can store, retrieve, remove, get, and put values in the dictionary by using the Java Dictionary class.


2 Answers

you can use HashMap like this

Map <String,String> map =  new HashMap<String,String>(); //add items  map.put("3433fd","Siva"); //get items   String employeeName =(String) map.get("3433fd"); 
like image 149
confucius Avatar answered Oct 02 '22 07:10

confucius


You can use Bundle.

as it offers String to various types of Mapping.

Bundle b = new Bundle(); b.putInt("identifier", 121); b.putString("identifier", "Any String"); b.putStringArray("identifier", stringArray);  int i = b.getInt("identifier"); ... 
like image 42
Adil Soomro Avatar answered Oct 02 '22 06:10

Adil Soomro