gpt4 book ai didi

java - map 的大小限制为 3 个元素

转载 作者:行者123 更新时间:2023-12-01 08:05:29 24 4
gpt4 key购买 nike

我正在尝试用 Java 填充 map ,但由于某种原因,它不允许 map 拥有超过 3 个元素,即使我想要更多。我该如何解决这个问题?

这是java代码,它恰好位于spring mvc应用程序的 Controller 方法中:

@ModelAttribute("addLinkOptions") 
public Map loadLinkOptions(){
LinkedHashMap<String, String> addLinks = new LinkedHashMap<String,String>();
addLinks.put("/calendar?day=2014-01-10","New this");
System.out.println(" ......1 size of addlinks is: "+addLinks.size());
addLinks.put("/","New that");
System.out.println(" ......2 size of addlinks is: "+addLinks.size());
addLinks.put("/otherlink","New some other thing");
System.out.println(" ......3 size of addlinks is: "+addLinks.size());
addLinks.put("/","New dog");
System.out.println(" ......4 size of addlinks is: "+addLinks.size());
addLinks.put("/","New cat");
System.out.println(" ......5 size of addlinks is: "+addLinks.size());
addLinks.put("/","New Car");
System.out.println(" ......6 size of addlinks is: "+addLinks.size());
addLinks.put("/","New lizard");
System.out.println(" ......7 size of addlinks is: "+addLinks.size());
addLinks.put("/","New bike");
System.out.println(" ......8 size of addlinks is: "+addLinks.size());
addLinks.put("/","New motorcycle");
System.out.println(" ......9 size of addlinks is: "+addLinks.size());
addLinks.put("/","New frog");
System.out.println(" ......10 size of addlinks is: "+addLinks.size());
return addLinks;
}

......1 size of addlinks is: 1
......2 size of addlinks is: 2
......3 size of addlinks is: 3
......4 size of addlinks is: 3
......5 size of addlinks is: 3
......6 size of addlinks is: 3
......7 size of addlinks is: 3
......8 size of addlinks is: 3
......9 size of addlinks is: 3
......10 size of addlinks is: 3
......10 size of addlinks is: 3

最佳答案

map 是一个键/值存储,每个键都是唯一的,使用相同键添加值将覆盖该键之前的值。

关于java - map 的大小限制为 3 个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22056189/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com