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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:37:44+00:00 2026-06-04T13:37:44+00:00

I did search on internet, but still don’t understand, so I ask this question

  • 0

I did search on internet, but still don’t understand, so I ask this question here.

in the small program below, I created two tour instance, all I want to do is putting tour[2] in without changing “Tour tour[]=new Tour[2];”.

A lot of people recommend ArrayList, but I don’t know how to do it in this code.

class Test{
public static void main(String args[]){

    class Tour{
        private String tourId;
        private String tourDescription;
        private double tourFee;
        private int numOfBooking;

        public Tour(String tourId,String tourDescription,double tourFee){
            this.tourId=tourId;
            this.tourDescription=tourDescription;
            this.tourFee=tourFee;
        }

        public void print(){
            System.out.println("ID:"+this.tourId);
            System.out.println("Desc:"+this.tourDescription);
            System.out.println("Fee:"+this.tourFee);
        }
    }


    Tour tour[]=new Tour[2];
    tour[0]=new Tour("AB001","TOUR1",100);
    tour[1]=new Tour("AB002","TOUR2",200);
}
}
  • 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-04T13:37:46+00:00Added an answer on June 4, 2026 at 1:37 pm

    As you discovered, arrays are indeed fixed length, and as such I would definitely recommend an ArrayList. Use it like this…

    ArrayList<Tour> tours = new ArrayList<Tour>();
    tours.add(new Tour("AB001","TOUR1",100));
    tours.add(new Tour("AB002","TOUR2",200));
    

    Every time you want to add a new Tour, just call tours.add() again.

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

Sidebar

Related Questions

I'm new to Stack and this is my first question, but I did search
I guess this might have been posted somewhere, I did search, but couldn't find
I have looked around stackoverflow and search the internet but did not find a
I tried this question before and did not supply enough information, so here are
I did search before posting this question and didn't find anything directly related, so
This might be a duplicate question, however I did search and I got so
I did search for this topic, but I didn't find any relevant clue for
I search on internet but did not find any best solution, i found one
I did search on this but the keywords must be too generic to narrow
I did search the internet to find an answer to my questions but 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.