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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:22:02+00:00 2026-06-13T11:22:02+00:00

Im trying to list the items in an array list from another class. I

  • 0

Im trying to list the items in an array list from another class.

I have 3 classes in total

Tell – The main program

Item – The class that creates individual telephone directory items

Directory – A directory object which stores all the items.

What I’m trying to do is list all the items within the array list created in “directory” and im doing it like this….

TELL

if (Directory.entries.size>0)
{
     for (int i=0; i<Directory.entries.size(); i++) // Check size of array
     {
           Directory.entries.get(i).showRecord();
     }
}

DIRECTORY

public void printItem()      
{
     //I HAVE NO IDEA WHAT GOES HERE
}

ENTRY

public class Entry
{
String name;
String telNo;
public Entry(String aName, String aTelNo )
{
    setNumber(aTelNo);
    setName(aName);
}
// Add methods here
private void setNumber(String aTelNo)
{
    telNo = aTelNo;
}

public String getNumber()
{
    return telNo;
}

private void setName(String aName)
{
    name = aName;
}

public String getName()
{
    return name;
}

public String toString()
{
    return name + "." + telNo;
}


}

However I havnt got the foggiest what needs to go in the printItem() Method to allow me to print the individual items in the directory.

Could someone point me in the right direction? This is the first time I have ever really used array lists accross multiple classes and I’m very confused.

  • 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-13T11:22:03+00:00Added an answer on June 13, 2026 at 11:22 am

    Since you have overrided the toString in your Entry class, so what all you need to do is iterate over your List and print each item. It will automatically invoke the toString of your Entry class and print the returned value: –

    Put this code in your print method, which is in Directory class.

    public static void print() {
        for (Entry entry: Directory.entries) {
            System.out.println(entry);
        }
    }
    

    entries is the static list you have in your Directory class.

    And from your Tell class, just invoke your print method:-

    Directory.print();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to have a tableview that leads to another tableview whose list
I'm trying to have a generic 'List' class, which will have: Property: Items -
I'm trying to fetch items from an array. So here's what my list look
I'm trying to bind a XAML ComboBox so that its list items are the
I am trying to display a list of items in a datagrid from an
I'm trying to read a list of items from a text file and format
I am trying to create a listview that receives a flagged list of items
I am trying to read in a file that has HTML list items with
i'm trying to create a list of the items from my database. the problem
I am trying to display a list of items I am getting from a

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.