简体   繁体   中英

Value in a map contains another map

For example below map name is TEST :

{
  name : 1
  place : 2
  others : {marks : 100 , rank : 200 }
}

I am unable to get value of others as a separate map.

Map<String,Object> final = TEST.get('others'); //It throws class cast exception

How to get value of others in a separate map?

If you have created the test map in such a way

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

then you can get the value using for(Entry<String,Map<String,String>> testsample : Test.entryset()) then u can use testsample.entryvalue to get the map inside it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM