Java创建LinkedHashMap
我想创建LinkedHashMap,其中将有另一个LinkedHashMap,如下所示:Java创建LinkedHashMap,java,arrays,hashmap,Java,Arrays,Hashmap,我想创建LinkedHashMap,其中将有另一个LinkedHashMap,如下所示: Array ( [width] => 450 [height] => 450 [file] => D:/images/bolivia-gonzales1.jpg [sizes] => Array ( [medium] => Array (
Array
(
[width] => 450
[height] => 450
[file] => D:/images/bolivia-gonzales1.jpg
[sizes] => Array
(
[medium] => Array
(
...
)
)
[twentyseventeen-thumbnail-avatar] => Array
(
...
)
)
我的代码是:
LinkedHashMap imagesArray = new LinkedHashMap();
imagesArray.put("width", image.getWidth());
imagesArray.put("height", image.getHeight());
imagesArray.put("file", destinationFile);
Set arrayList = new HashSet();
LinkedHashMap thumbnail = new LinkedHashMap();
thumbnail.put("file", newUrl150);
thumbnail.put("width", image.getWidth());
thumbnail.put("height", image.getHeight());
thumbnail.put("mime-type", "image/jpeg");
LinkedHashMap thumbnailMap = new LinkedHashMap();
thumbnailMap.put("thumbnail", thumbnail);
arrayList.add(thumbnailMap);
LinkedHashMap medium = new LinkedHashMap();
medium.put("file", newUrl300);
medium.put("width", out.getWidth());
medium.put("height", out.getHeight());
medium.put("mime-type", "image/jpeg");
LinkedHashMap mediumMap = new LinkedHashMap();
mediumMap.put("medium", medium);
arrayList.add(mediumMap);
imagesArray.put("sizes", arrayList);
我得到这个数组:
Array
(
[width] => 450
[height] => 450
[file] => D:/images/bolivia-gonzales1.jpg
[sizes] => Array
(
[0] => Array
(
[medium] => Array
(
...
)
)
[1] => Array
(
[twentyseventeen-thumbnail-avatar] => Array
(
...
)
)
正如您在“size”中看到的,有键为[0]、[1]的数组
如何构建没有[0]、[1]键的LnkedHashMap
我尝试使用不同的列表、贴图和集合,但不幸的是,所有这些都使用“键”为我提供了输出。您所说的是在另一个贴图中创建贴图,但在imagesArray贴图中放置了一个集合。只需在其中使用map,就可以在将一个键放入另一个键时定义键 你说的如何构建LnkedHashMap是什么意思,它没有[0]、[1]键?。地图是成对的集合。