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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:12:54+00:00 2026-05-30T20:12:54+00:00

I have these two classes: class Student { String name; String age ; }

  • 0

I have these two classes:

class Student
{
String name;
String age ;
}

class Person
{

String name;
String age ;
String grade ;
}

In the code below, I am creating Student objects and setting them inside the ArrayList. Once the data is set in the ArrayList, I need to parse that ArrayList and set the values in another object:

public class Work {

    public static void main(String args[]) {

        List StudentItems = new ArrayList();

        Student stud1 = new Student();
        Student stud2 = new Student();

        stud1.name = "ABC";
        stud1.age = "28";
        stud2.name = "XYZ";
        stud2.age = "38";

        StudentItems.add(stud1);
        StudentItems.add(stud2);

        Person[] pers = new Person[StudentItems.size()];

        for (int i = 0; i < StudentItems.size(); i++) {
            pers[i] = new Person();

// I am confused here , could anyone please help 

        }

    }
}
  • 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-30T20:12:55+00:00Added an answer on May 30, 2026 at 8:12 pm

    Try it out. This will do the work

    Your Person class should be something like this:

    package com.student.person.work;
    
    /**
     *
     * @author sarath_sivan
     */
    public class Person {
    
        private String name;
        private int age;
        private String grade;
    
        public String getName() {
           return this.name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public int getAge() {
            return this.age;
        }
    
        public void setAge(int age) {
            this.age = age;
        }
    
        public String getGrade() {
            return this.grade;
        }
    
        public void setGrade(String grade) {
            this.grade = grade;
        }
    
    }
    

    Your Student class should be something like this:

    package com.student.person.work;
    
    /**
     *
     * @author sarath_sivan
     */
    public class Student {
    
        private String name;
        private int age;
    
        public String getName() {
           return this.name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public int getAge() {
            return this.age;
        }
    
        public void setAge(int age) {
            this.age = age;
        }
    
    }
    

    And finally, the Work class:

    package com.student.person.work;
    
    import java.util.ArrayList;
    import java.util.List;
    
    /**
     *
     * @author sarath_sivan
     */
    public class Work {
    
        public static String calculateGrade() {
            String grade = "";
            // Your code to find the grade.
            //............
            return grade;
        }
    
        public static void doWork() {
            List<Student> studentList = new ArrayList<Student>();
    
            Student student = new Student();
            student.setName("ABC");
            student.setAge(24);
            studentList.add(student);
    
            student = new Student();
            student.setName("DEF");
            student.setAge(28);
            studentList.add(student);
    
            student = new Student();
            student.setName("GHI");
            student.setAge(21);
            studentList.add(student);
    
            List<Person> personList = new ArrayList<Person>();
    
            for(Student students : studentList) {
                Person person = new Person();
                person.setName(students.getName());
                person.setAge(students.getAge());
                person.setGrade(Work.calculateGrade());// Setting the grade
            }
        }
    
        public static void main(String[] args) {
            Work.doWork();
        }
    
    }
    

    Hope this will be helpful.

    Thank you!

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

Sidebar

Related Questions

I have these two classes public class Person { } public class Company {
Let's say we have these two classes: public class Base { public static int
I have two classes, a Teacher class and a Student class. In my program
I have this weird situation. I have these two classes: Public Class Entry End
If I have these two classes: class A {} class B : A {}
I have these two entities. One for Employees: [Table(Name = Employees)] public class Employee
Say you have these two classes. public class Author { public int ID {get;
I have a problem with these two classes: Creature: public abstract class Creature extends
Ok, I need a little help. I have these two PHP classes class menu
Suppose we have declared these two classes: public class Animal { //..... } public

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.