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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:13:57+00:00 2026-05-23T14:13:57+00:00

Assuming Sports , School , Home are classes in Java. with Home having a

  • 0

Assuming Sports, School, Home are classes in Java.
with Home having a method e.g.

void add(Sports t1, School t2);

Here is what i want to do:

Sports s1 = new Sports("value1");
School t2 = new School("value1");
Home h = new Home();
h.add(s1,t2);

Now the problem is, i want to repeat these steps too many times. with h remaining the same. So that h.add() is called multiple times with different objects as parameters with values coming from outside using forloop.
can someone show me how can i initialize these objects and call
the add method in e,g a for loop with different object names in
each iteration?

  • 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-23T14:13:57+00:00Added an answer on May 23, 2026 at 2:13 pm

    Here is where you will want to use arrays (or lists).

    Example:

    Home h = new Home();
    Sports[] sports = new Sports[10];
    School[] schools = new School[10];
    for (int i =0; i< sports.length; i++) {
        h.add(sports[i], schools[i]);
    }
    

    In the above example you will need a way to initialize the contents of the sports and schools arrays.

    Perhaps this slight variation of above is what you need:

    Home h = new Home();
    String[] sports = // existing array of sport names
    String[] schools = // array of school names
    for (int i =0; i< sports.length; i++) {
        h.add(new Sports(sports[i]), new School(schools[i]));
    }
    

    Here we use arrays of school and sport names to create all of the objects that get added to Home.

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

Sidebar

Related Questions

Assuming I'm trying to automate the installation of something on windows and I want
Assuming I have a class with a method that takes a System.Linq.Expressions.Expression as a
Assuming the following module which allows to add acts_as_timeable functionality to an arbitrary model.
Assuming the URL is http://localhost:8080/project-name/resource.xhtml , I want to obtain the following http://localhost:8080/project-name in
Assuming I want to get 3 documents which fit one of these attributes Class
I'm trying to write a method to compare two arrays in Java without using
Assuming i got 3 data:i=01,j=02,k=03 and i want to set these 3 data indiviually
Assuming such a query exists, I would greatly appreciate the help. I'm trying to
Assuming you can't use LINQ for whatever reason, is it a better practice to
Assuming there are 5 items in the settings file ( MySetting1 to MySetting5 ),

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.