提问人:Mohil M 提问时间:11/3/2023 最后编辑:Mohil M 更新时间:11/3/2023 访问量:49
我想通过在映射中保持 arraylist 的键值对相同来将自定义 java 对象的 arraylist 转换为 hashmap [closed]
I want to convert arraylist of custom java object to hashmap by keeping key-value pair of arraylist same in the map [closed]
问:
这是我从 db 获取的列表(将来可以通过添加更多变量在 db 中更新:
response
{
"nameField1" : "nameLabel1",
"numberField2": "numberLabel2"
}
我希望结果 map<String, String> 看起来像这样:
{nameField1=nameLabel1, numberField2=numberLabel2 }
答:
1赞
wolginm
11/3/2023
#1
跟进吉姆·加里森(Jim Garrison)的帖子,看看这个,Baeldung - Using Jackson。此库应帮助您将通用对象转换为映射。这些对象位于 ArrayList 或任何形式的列表中,并不会使它变得更加困难。
评论
0赞
Mohil M
11/3/2023
谢谢wolginm&@Jim Garrison。它就像一个魅力。
评论