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 8826423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:08:01+00:00 2026-06-14T07:08:01+00:00

What is the best way to store an element that has multiple elements? As

  • 0

What is the best way to store an element that has multiple elements? As in a 6d array.
I have seen something along the lines of ArrayList(ArrayList(ArrayList(ArrayList))), but don’t have a clue as to how or mostly why it would be configure as such or how to access the elements!

As an example, I want to create an array(list) that stores the following information:

house id, house number, street name, residents, owner first name, owner last name

I would like to be able to sort and search on anyone of the sub-elements in the main record element.

What I have done is create an arraylist that contains an arraylist for each of these. Basically I have a class called HouseArray that has a method called CreateArray. From my class GUI, I have

houses = new HouseArray();
houses.CreateArray();

In class
HouseArray, my method CreateArray has

ArrayList<Integer> entryID;
ArrayList<Integer> houseNum;
ArrayList<String> streetName;
ArrayList<Integer> residents;
ArrayList<String> firstName;
ArrayList<String> lastName; 

entryID = new ArrayList();
houseNum = new ArrayList();
streetName = new ArrayList();
residents = new ArrayList();
firstName = new ArrayList();
lastName = new ArrayList(); 

and then I use an AddEntry method that puts data into each arraylist.

this.entryID.add(12345);
this.houseNum.add(9876);
this.streetName.add("My Street");
this.residents.add(4);
this.firstName.add("John");
this.lastName.add("Jones");

I am at a loss at how I would be able to sort this mess and keep the entries synchronized without manually writing a lot of coding to do it all. Also, I want to be able to sum the number of residents that live on a particular streetName or total the number of residents that live in houses owned firstName or lastName.

Am I on the right track or is there a better way to do this?
Teaching myself java, so not sure if this counts as homework.

  • 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-06-14T07:08:03+00:00Added an answer on June 14, 2026 at 7:08 am

    As an example, I want to create an array(list) that stores the
    following information:

    house id, house number, street name, house color, owner first name,
    owner last name

    the best approach is to create a Class name it House and have these attributes as its state.

    class House {
    
    private long houseId;
    private long hNo;
    private String streetname;
    private String color;
    private String owner;
    private String firstName;
    public House(long houseId, long hNo, String streetName, String color, String owner, String firstName){
      //initialize your instance variables here
    

    }

     public void setHouseId(long houseId){
      this.houseId = houseId;
      }
     //do the same thing for reamining attributes
     //getters and setters for all the attributes.
    }
    

    now, create a java.util.List which holds House Object.

    List<house> houseList = new Arraylist<>();
    //and populate the list with house objects.
    House house1 = new House(123,223,"Bond Street", "Green","James Bond", "James");
    list.add(house1);
    

    This approach is more Object-Oriented way of doing things, as House represents an Object which has state and behaviour.However, if you want to sort your House elements in your arrayList you will have to override equals and hashcode methods.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What's the best way to store ordered lists in a database, so that updating
What is the best way to store sound files (ogg) that are distributed with
What is the best way to store data that is dynamic in nature using
What's the best way to store a key=>value array in javascript, and how can
I have roughly 420,000 elements that I need to store easily in a Set
The best way to store images into MySQL is by storing the image location
What is the best way to store a 2D matrix of integers in Java?
What is the best way to store and handle sensitive information with puppet and
What's the best way to store connection string info? I'd rather not just store
What is the best way to store a list of random numbers (like lotto/bingo

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.