arraylist - Casting list of objects to list of maps in java -


this question has answer here:

i'm having list of objects this.

[     [     "abhay pawde",     "development"     ],     [     "dinesh",     null     ] ] 

i want convert them list of maps example mentioned below:

[     [     "name":"abhay pawde",     "dept":"development"     ],     [     "name":"dinesh",     "dept":null     ] ] 

how achieve in java ? i'm not sure if there other solution mentioned here. please let me know. list of objects obtained after querying database.

you could collect map using jdk-8 features, like:

 yourlist.stream()         .map(collectors.tomap(yourobject::getname, yourobject::getdepartment)) 

Comments

Popular posts from this blog

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

javascript - Confirm a form & display message if form is valid with JQuery -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -