当前位置:网站首页>Map value
Map value
2022-06-26 13:12:00 【shmilyhq】
main Method
public static void main(String[] args) {
try {
String json = "[
{
"user1":{
"12":"age1",
"23":"age2",
"34":"age3"}
},
{
"user2":{
"90":"scrouse1",
"87":"scrouse2",
"98":"scrouse3"}
}]";
JSONArray jsonArray = JSONArray.parseArray(json);
for (Object object : jsonArray) {
Map<String, Object> map = JSONObject.parseObject(JSON.toJSONString(object));
} catch(Exception e){
}
}
}
demo1 according to entrySet() Get all using iterators value value ( Higher performance )
private void handler (Map < String, String > map){
Iterator<Map.Entry<String, Object>> entryIt = map.entrySet().iterator();
while (entryIt.hasNext()) {
Map.Entry<String, Object> entity = entryIt.next();
Map<String, String> entityValue = (Map<String, String>) entity.getValue();
Iterator<Map.Entry<String, String>> entryIt = entityValue .entrySet().iterator();
while (entryIt.hasNext()) {
Map.Entry<String, String> entity = entryIt.next();
String val = entity.getValue();
String busType = entity.getKey();
System.out.println(busType + val);
}
}
}
demo2
private void handler (Map < String, String > map){
for(String k : map.keySet()){
Map<String, String> entityValue = (Map<String, String>) map.get(k);
for(String k2 : entityValue .keySet()){
System.out.println(k2+ entityValue .get(k2));
}
}
}
The following two are not recommended
demo3 adopt Map.entrySet Traverse key and value, Recommended for large capacity
private void handler (Map < String, String > map){
for(Map.Entry<String, String> entry : map.entrySet()){
Map<String, String> entityValue = (Map<String, String>) map.getValue;
for(Map.Entry<String, String> entry : entityValue.entrySet()){
System.out.println(k2+ entityValue .get(k2));
}
}
}
demo4 according to keySet() Get all using iterators value value ( Low performance )
private void handler (Map < String, String > map){
Iterator<String> it = map.keySet().iterator();
while(it.hasNext()){
String key = it.getKey();
Map<String, String> entityValue = (Map<String, String>) map.get(key );
Iterator<String> it2 = entityValue .keySet().iterator();
while(it2 .hasNext()){
String key2 = it2.getKey();
System.out.println(key2 + it2.get(key2 ));
}
}
}
Reprint https://blog.csdn.net/qq_19694251/article/details/113524049
边栏推荐
- Electron official docs series: Best Practices
- Enjoy element mode (flyweight)
- Solution of Splunk iowait alarm
- Don't mess with full_ Case and parallel_ CASE
- National standard gb28181 protocol easygbs video platform TCP active mode streaming exception repair
- map 取值
- Uva10341 solve it
- opencv高速下载
- 软件测试报告应该包含的内容?面试必问
- 外观模式(Facade)
猜你喜欢
随机推荐
享元模式(Flyweight)
Power Designer - Custom Comment button
黑马笔记---常用API
倍福PLC通过MC_ReadParameter读取NC轴的配置参数
倍福TwinCAT3 NCI在NC轴界面中的基本配置和测试
C# 结构体:定义、示例
Script - crawl the customized storage path of the cartoon and download it to the local
D - skiing
To solve the difficulties of small and medium-sized enterprises, Baidu AI Cloud makes an example
Electron official docs series: Get Started
HDU 5860
倍福PLC通过程序获取系统时间、本地时间、当前时区以及系统时间时区转换
Coprime and non coprime of template problems of Chinese remainder theorem
Word document export (using fixed template)
Go structure method
First knowledge - Software Testing
Angle de calcul POSTGIS
详细讲解C语言11(C语言系列)
Prototype
Arcpy - - utilisation de la fonction insertlayer (): ajout de calques dans un document de carte