我有一個多個ArrayList的航點的問題。 我有一艘船。 一艘船有航點。ArrayList的二維陣列列表
public static ArrayList<Waypoint> _waypoints = new ArrayList<>();
要添加新的航點我用
Screen._waypoints.add(
new Waypoint(
12,20
)
);
Screen._waypoints.add(
new Waypoint(
15,50
)
);
Screen._waypoints.add(
new Waypoint(
17,90
)
);
這意味着:
- 船舶 - > 12,20
- 船舶 - > 15,50
- 船舶 - > 17,90
我修改了我的遊戲,並添加了船型,這意味着每種類型的船都有不同的航點。
我修改了航點的初始化。
public static ArrayList<ArrayList<Waypoint>> _waypoints = new ArrayList<ArrayList<Waypoint>>();
我想創建這樣的結構:
船舶 - >木材 - >航點
例如數組列表我有兩種類型的船 - >木材和海盜船。
船舶 - >木材
- 船舶 - > 12,20
- 船舶 - > 15,50
- 船舶 - > 17,90
船舶 - >海盜
- 船 - > 12,20
- 艦 - > 15,50
- 船舶 - > 17,90
爲了讓我想用這個木材的ArrayList中:
waypoints.get("wood");
我不知道如何實現它使用的ArrayList中
由於二維數組列表,
你正在尋找一個[圖](http://docs.oracle的.com/JavaSE的/ 6 /文檔/ API/JAVA/util的/ Map.html)。雖然說實話像靜態一樣保持數據是一種代碼味道。但是,是的,使用地圖代替。 – Perception
你可以使用'Map'和''wood''並且'pirate'將會是你的密鑰,'ArrayList'將會與它相關聯。 –
kaysush