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

  • SEARCH
  • Home
  • 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 7590815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:29:55+00:00 2026-05-30T20:29:55+00:00

Hey how do I access an arraylist from another class? as in call an

  • 0

Hey how do I access an arraylist from another class? as in call an objects method inside of the arraylist but from the MasterControlPanel class?. Any help is greatly appreciated. Because the get(0) does not seem to be working.

//example

public class MasterControlPanel{
    public static Building building = new Building();

    public static void main(String[] args) {
        building.rooms.get(0).*whatever*
    }
}

public class Building
{
    public static Rooms rooms[] = new Rooms[4];
    private float outsideTemp;
    ArrayList rooms = new ArrayList();

    rooms.add(*new instance*); 
    rooms.add(*new instance*); 

    public Building() {
    }

}

  • 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-30T20:29:56+00:00Added an answer on May 30, 2026 at 8:29 pm

    Add a getter:

    public class Building{
    
    public static Rooms roomArray[] = new Rooms[4];
    private float outsideTemp;
    List<Room> rooms;
    
    public Building(float temp){
        rooms = new ArrayList<Room>();
        rooms.add(new Room()); 
        rooms.add(new Room());
        outsideTemp = temp;
    }
    
    public List<Rooms> getRoomList() {
        return this.rooms;
    }
    }
    

    Then you can do:

    public class MasterControlPanel{
        public static Building building = new Building();
    
        public static void main(String[] args){
        building.getRoomList.get(0).*whatever*
    
        }
    }
    

    Aside: why aren’t you defining the type of your Lists? Also, note that I’ve moved code into the Constructor for this class, and fixed name collisions. Also, why the static array? Things to think about…

    Last note: added float to constructor to ensure it’s initialized.

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

Sidebar

Related Questions

Hey, I can't seem to access the returned value from a method I called
Hey I'm trying to access an object I've made in the main method from
hey I am getting an error accessing unknown class method 'setFirstName' but I am
Hey, I'm struggling to copy the Primary Key to another field in Access. This
hey guys i want to fetch 3 tables in 1 single ado.net call from
Hey I need a little help with unsigned char bit access. I need to
Hey I'm using the ExeConfigurationFileMap class's OpenMappedExeConfiguration method to open a config file. The
Hey guys I have enabled APC on my VPS but now I can't access
Hey, I want to access the Android call list, so I can see the
Hey there, I am trying to access raw data from iphone camera using AVCaptureSession.

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.