【问题标题】:Java create LinkedHashMapJava 创建 LinkedHashMap
【发布时间】:2018-09-21 11:35:07
【问题描述】:

我想在其中创建另一个 LinkedHashMap,如下所示:

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
                        (
                            ...
                        )

                )

正如您在“大小”中看到的,有键为 [0]、[1] 的数组。

如何构建没有[0]、[1]键的LnkedHashMap?

我尝试使用不同的列表、地图、集合,但不幸的是,所有输出都带有“Key”

【问题讨论】:

  • 如何构建没有 [0]、[1] 键的 LnkedHashMap 是什么意思?。地图是一个 配对集合。

标签: java arrays hashmap


【解决方案1】:

您说的是在另一个 Map 中创建一个 Map,但您是在 imagesArray Map 中放置一个 Set。只需在其中使用 map ,当您将一个放在另一个内部时,您可以定义键。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-07
    • 2015-06-20
    • 2011-08-19
    • 2013-01-05
    • 2010-10-26
    • 2020-09-02
    • 1970-01-01
    相关资源
    最近更新 更多