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

The Archive Base Latest Questions

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

when this program is run , i am getting only one name , instead

  • 0

when this program is run , i am getting only one name , instead of two
That is the output is Pavan only

import java.util.ArrayList;
import java.util.List;

public class Work {

    public static void main(String args[]) {

        User user1 = new User();
        User user2 = new User();

        user1.setName("Pavan");
        user2.setName("Palla");

        List userItems = new ArrayList();
        userItems.add(user1);
        userItems.add(user2);

        UserlistItem[] userlistitem = new UserlistItem[userItems.size()];

        for (int i = 0; i < userItems.size(); i++) {

            User user = (User) userItems.get(i);

            userlistitem[i] = new UserlistItem();

            userlistitem[i].setUser(user);

        }

        Userlist userlistm = new Userlist();
        userlistm.setUserlistItem(userlistitem);

        UserlistItem[] ravi = userlistm.getUserlistItem();

        Userlists lists = new Userlists();

        lists.setUserlist(new Userlist[] { userlistm });

        Userlist[] main = lists.getUserlist();

        for (int i = 0; i < main.length; i++) {
            System.out.println("Pavan"
                    + main[i].getUserlistItem()[i].getUser().getName());
        }


}

public class User {

     private String      name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

}


public class UserlistItem {
    private User user;

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    } 


}



import java.io.Serializable;

public class Userlist {

    private static final long serialVersionUID = 1L;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public UserlistItem[] getUserlistItem() {
        return UserlistItem;
    }

    public void setUserlistItem(UserlistItem[] userlistItem) {
        UserlistItem = userlistItem;
    }

    private String id;
    private UserlistItem[] UserlistItem;

}



public class Userlists {

    private Userlist[] userlist;

    public Userlist[] getUserlist() {
        return userlist;
    }

    public void setUserlist(Userlist[] userlist) {
        this.userlist = userlist;
    }

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

    Firstly, why don’t you debug your code by putting a breakpoint to the line where the printing happens? In the 2nd for loop of your main method, main.length is 1. Change the loop to the code below, it will be done. But your code is confusing, I’m not sure how you will track more objects of your defined classes.

    for (int i = 0; i < main[0].getUserlistItem().length; i++) {
        System.out.println("Pavan"
                + main[0].getUserlistItem()[i].getUser().getName());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to run this line from my c++ program: java -jar test.jar text1
This is my problem. I have a program that has to run in a
I need to make sure that user can run only one instance of my
This program I use has it's own variables to set when you run it,
To run a program with custom env settings, we do this on Linux $
I've run into this while writing a Traveling Salesman program. For an inner loop,
Is there a program which I can run like this: py2py.py < orig.py >
when I call Application.Run() on a form, this command halts the program until the
I have this program that is reading the test string from a textbox and
I am getting this exception sometimes when my program is starting connection to MS

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.