在Java中动态命名ArrayList

时间:2017-08-08 03:58:46

标签: java json arraylist hashmap

假设我有一个json

{
  "data": {
    "json": [

      {
        "value": [
          "john","joy"
        ],
        "key": "Names"
      },

      {
        "value": [
          "25A",
           "26B"
        ],
        "key": "john"
      },

      {
        "value": [
          "27A",
          "28B"
        ],
        "key": "joy"
      }
    ]
  }
}

我想为每个值创建一个Dynamic ArrayList名称,如下所示

for(String name:Names){
  //create a dynamic arraylist from the names here like 
 // ArrayList<String> joy= ..........
}

有人可以帮我这个吗?

1 个答案:

答案 0 :(得分:1)

也许使用

Map<String, List<String>> map = new HashMap<String, List<String>>();
map.put("arrayname", new ArrayList<String>());