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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:26:17+00:00 2026-05-14T15:26:17+00:00

i have to create a list of ,let’s say 50 people, (in Java) and

  • 0

i have to create a list of ,let’s say 50 people, (in Java) and display the list, and i don’t really know how to do that. so this is what i have tried to do so far . please correct and complete some of my code .

public class Person {

    String name;
    String stuff;
}


public class CreatePerson {



public static void  ang()  {    

    ArrayList<Person> thing=new ArrayList<Person>(); 
    Scanner diskScanner = new Scanner(in);


    for(int i=0; i<50; i++){

        Person pers = new Person();

          out.print("name: ");
      pers.name=diskScanner.nextLine();

      out.print("stuff: ");
      pers.stuff=diskScanner.nextLine();

      thing.add(pers);

          break;

    }
    // Display people  
    for (int i=0; i<50; i++) {
        out.println(??);{
        }

} }}
  • 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-14T15:26:18+00:00Added an answer on May 14, 2026 at 3:26 pm

    Looks fine to start.

    I’m going just to suggest a couple of things:

    1.- Import the out attribute from System:

    import static java.lang.System.out;
    

    2.- In the for loop remove the break

    ...
    for(int i=0; i<50; i++){
        Person pers = new Person();
        out.print("name: ");
        pers.name=diskScanner.nextLine();
        out.print("stuff: ");
        pers.stuff=diskScanner.nextLine();
        thing.add(pers);
        break; //<-- Remove this to continue with the remaining 49 persons
    }
    

    3.- Finally you could print the values like this:

    // Display people  
    for (int i=0; i<50; i++) {
        //out.println(??);{
        //}
        // could be:
        out.println("name: "+ thing.get(i).name +" stuff:"+thing.get(i).stuff );
    }
    ...
    

    edit

    Alternatives for the print:

    // introduce a variable p 
    for (int i=0; i<50; i++) {
        Person p = thing.get(i);
        out.println("name: "+ p.name +" stuff:"+p.stuff );
    }
    

    Or

    // using the size of the array and printf.. 
    for (int i=0; i<thig.size(); i++) {
        Person p = thing.get(i);
        out.printf("name: %s stuff: %s %n", p.name ,p.stuff );
    }
    

    Or even better ( my preferred )

    // using the for-each syntax
    for( Person p : thing ) {
          out.printf("name: %s stuff: %s %n", p.name ,p.stuff );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let say I have Customers table in a database. I'd like to create List
I want to create a list of columns in SQL Server 2005 that have
How would I create a nested list, I currently have this public function getNav($cat,$subcat){
I have a list of actions on various controllers that are 'Admin' functions (create,
Let's say in Perl I have a list of hash references, and each is
Let's say I have a function with a signature like this: def tsadd(key: Any,
Let's say we have a List<Product> and each product item in the list has
Let's say I have a list of objects of the same type. I want
Let's suppose that I have a list of elements, and I want to select
I want to implement a 'favorite list' and let's assume that I have got

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.