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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:11:53+00:00 2026-05-28T05:11:53+00:00

I have a class, lets call it ‘Words’, that reads a file and creates

  • 0

I have a class, lets call it ‘Words’, that reads a file and creates a list of strings.

I then have a class, ‘Items’, that creates a list of ‘description’ objects, each description object needs access to the list from ‘Words’.

Since the ‘Word’ list reads a file, I obviously don’t want to create that list for each ‘description’ object. So what would be the best way of accessing that list?

Should I just create a function getList() from ‘Words’ and pass it to ‘Items’ constructor, then pass it again to each ‘description’? or is there a better way? If I do that, then I would also want to make sure it is only a reference to the list and not a copy since the ‘Words’ list can get huge.

I am relatively new to java and any help would be appreciated.

  • 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-28T05:11:53+00:00Added an answer on May 28, 2026 at 5:11 am

    You need to create a class that pupulate the List of String object (singleton), call that singleTon method in constructor of description class to assign reference of list to the description object.

    public class Words
    {
       private static ArrayList<String> words;
       public static ArrayList<String> getWords() 
       {
          if(words==null) 
            {
              words=new ArrayList<String>();
              //read strings from the file and add them into list
            }
          return words;
        }
    }
    

    In description class,

    public class Description
    {
       private String desc;
       private ArrayList<String> words;
    
       public Description(String desc) 
        {
            this.desc=desc; 
            this.words=Words.getList();
         }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that extends Zend_Db_Table lets call it 'Users' that uses the
I have a UIImageView based class (lets call it classA) that uses a classB
I have a class, lets call it A, and within that class definition I
I have a class that has a complex static factory method, lets call it
I have an attribute lets call it SomeAttribute and a class i need to
I'm new to django. I have 2 simple objects, lets call them - File
I have an ActiveRecord class - lets call it comments - which has an
I have a class of mine, lets call it TMyObject, which should return a
I have this class mapped as a entity, lets call it Person. Person has
We have an entity (class) containing data and methods (lets call it Person). There

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.