简体   繁体   English

如何在不知道需要多少个 ArrayList 的情况下创建一个 Map 的 ArrayList?

[英]How can I create a Map of ArrayLists without knowing how many ArrayLists I will need?

The way my program works is it gets an arraylist of some object "World".我的程序的工作方式是它得到一些 object“世界”的 arraylist。 I want to create a new arraylist for every World.我想为每个世界创建一个新的 arraylist。 I then want to create a map where the name of a World is the key, and a arraylist is the value.然后我想创建一个 map ,其中 World 的名称是键,arraylist 是值。 So far, I can get an unique id for each World and the size of the arraylist of Worlds, but I don't know how to create that map.到目前为止,我可以获得每个世界的唯一 ID 和世界 arraylist 的大小,但我不知道如何创建 map。

You can use any of the classes that implement the Map interface, eg HashMap:您可以使用任何实现 Map 接口的类,例如 HashMap:

Map<String, ArrayList<World>> map = new HashMap<String, ArrayList<World>>();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM