How do I create nested lists in java? so I have a factory method below which will pass a list to the constructor of the ROOM class. But I need to associate each wall with a window, So when I iterate over the list in the constructor it knows that a certain window belongs to a certain wall?.
public static Room RoomU(){
List<Room> RoomU = new ArrayList<Room>();
// THESE TWO SHOULD BE PAIRED AND SO ON...
RoomU.add(new Walls(Height, Width));
RoomU.add(new Windows(Height,Width));
RoomU.add(new Walls(Height, Width));
RoomU.add(new Windows(Height,Width));
RoomU.add(new Walls(Height, Width));
RoomU.add(new Windows(Height,Width));
RoomU.add(new Walls(Height, Width));
RoomU.add(new Windows(Height,Width));
RoomU.add(new Walls(Height, Width));
RoomU.add(new Windows(Height,Width));
return new Room(RoomU);
}
What you are looking for is probably a Map, not List.
Looking at this again, I think that maybe you should refactor some more basic thing, and have the windows object inside the walls object: