How to convert a list object to a Map and iterate through Map

Posted on Updated on

Let us consider we have a list object named usersList, now our requirement is to convert this list object into map and iterate through the map.

Each List object is nothing but a row in the database table

We can understand this better with an example

for (Map<String, Object> map : usersList) {

JSONObject jsonObject = new JSONObject();

for (Map.Entry<String, Object> entry : map.entrySet()) {

String key = entry.getKey();

Object value = entry.getValue();


//product name is name of the coloumn in the database

jsonObject.put(“productName”, value);


else if(“CONTRACT_STATUS”.equals(key)){

jsonObject.put(“contractStatus”, value);


Here the iteration through the list means iterating through reach row


List—>L[0]—->Row—>C[0],V[0] ¬†(coloumn,Value)



Iterating through map takes place by iterating through each column of database and its corresponding value for that particular row in the list








Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s