Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7628207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:33:51+00:00 2026-05-31T05:33:51+00:00

How do I create nested lists in java? so I have a factory method

  • 0

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);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:33:52+00:00Added an answer on May 31, 2026 at 5:33 am

    What you are looking for is probably a Map, not List.

    Map<Walls, Windows> myMAp = new HashMap<Walls, Windows>();
    mMap.put(new Walls(1,2), new Windows(1,2));
    

    Looking at this again, I think that maybe you should refactor some more basic thing, and have the windows object inside the walls object:

    List<Walls> rooms = new ArrayList<Walls>();
    rooms.add(new Walls(1,2,new Windows(1,2)));
    
    //--- in Walls class:
    Windows windows;
    
    public Walls(int height, int width, Windows windows) {
        this.windows = windows;
        // the rest
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a nested list in Flex which will dynamically resize to
How would I create a nested list, I currently have this public function getNav($cat,$subcat){
I'm working on a navigation control. I have nested lists which creates this: What
I want to create a Java method, which accepts an inputArray = Object[n][] ,
Imagine a nested list as below. [A,ABBA,ABABA] I would like to create a function
I'm trying to create a tree from a list of tags which have tags
I have created a nested list with drag/drop functionality. My issue is that I
How would I create a nested grouping for the table below, using LINQ? I
Is it possible to create a nested looping query in Access DB that will
What is the best approach to create a nested grids ? //all ideas will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.