【发布时间】:2013-11-20 16:33:57
【问题描述】:
我有一个关于 Arraylist 中的 ArrayList 的问题。这是关于具有多个产卵的多个世界。我想一一检查每个世界,并将该世界的所有生成物保存在 ArrayList 中。最后,我有一个 ArrayList,在每个位置(每个位置都是一个世界)上都有另一个 ArrayList,其中包含该世界的生成物。
如果我不知道会有多少个出生点或世界,我该怎么做?我想到了这个:
只看一个世界:
public ArrayList<Location> Spawnpoints = new ArrayList<Location>();
//ArrayList containing all the spawns of this world).
寻找世界上的每一个产卵
Spawnpoints.add(new Location(spawnX , spawnY , spawnZ));
//Adding every spawn to the ArrayList spawnpoints.
所以在我查看了一个世界之后,我已经用位置填充了 ArrayList 生成点。现在我想将 ArrayList 生成点添加到一个新的 ArrayList 世界。 之后,我将为下一个世界重复上面的代码,直到我拥有所有的世界。
编辑。 我认为它正在工作。当我只有名字时,我很难获得列表的大小。
假设我这样做了:allSpawnpoints.put("yourWorld",Spawnpoints);
现在我想获取字符串 yourWorld 的 Spawnpoints 列表的大小。知道我该怎么做吗?
我试过了:int number = allSpawnpoints.get("yourWorld").size();
好像不行。
我希望有人可以帮助我!谢谢阅读。 问候。
【问题讨论】:
-
allSpawnpoints.get("yourWorld")将返回一个List<Location>..所以它就像List<Location> loc = allSpawnpoints.get("yourWorld"); loc.size()