如何在Java中存储项目的“多条信息”
我需要一个数据结构,将允许我存储每个项目至少2条数据。我希望项目按插入顺序存储
例如:
Insert (xyz, string) ... insert (789, number)
System.out.println( dataStruct );
将打印出(xyz, string)
,然后(789,number)
如果可能,请显示一些示例代码。谢谢大家!
你可以在下面搜索框中键入要查询的问题!
我需要一个数据结构,将允许我存储每个项目至少2条数据。我希望项目按插入顺序存储
例如:
Insert (xyz, string) ... insert (789, number)
System.out.println( dataStruct );
将打印出(xyz, string)
,然后(789,number)
如果可能,请显示一些示例代码。谢谢大家!
# 1 楼答案
这将以某种方式满足需求,您还可以在HashMap的构造函数中使用该类型的参数
# 2 楼答案
以下代码可以是您的数据结构:
# 3 楼答案
可以使用Hashtable或List
例如:
看看一些Java structures
编辑
为了保持插入顺序,可以使用LinkedHashSet或LinkedHashMap
# 4 楼答案
我想这就是你要找的。这是C型结构。试试这个。 这将帮助您只需做一些小的更改,就可以为每个项目插入2条以上的数据。秩序也将得到维持