Results 1 to 4 of 4
  1. #1
    xxdave is offline Member
    Join Date
    Nov 2011
    Location
    birkenhead
    Posts
    6
    Rep Power
    0

    Default Help on how to store details from one class into an Array of another class?

    Hi, I am pretty new to Java and just wondering how I can store a person's details from one class into an Array of another class. It also has to be an Array, NOT ArrayList as I already know how to do this :P

    My code so far:

    public class Member
    {
    private String surname;
    private String firstName;
    private String membershipCode;


    public Member(String firstName, String surname, String membershipCode)
    {
    this.firstName = firstName;
    this.surname = surname;
    this.membershipCode = membershipCode;
    }
    }

    // I also have the usual accessor methods, getName etc.

    Now this is my Website Class :

    public class Website
    {

    public Website()

    {
    String members[] = new String [10]; // Fixed size

    }
    }

    I Basically want to create a member object from "Member class" and store it in the "members Array". And then create another member object untill the fixed array size is full.

    I think I am trying to over complicate things?

    Any help will greatly be appreciated!

    Thank you in advance

  2. #2
    Kuttappu's Avatar
    Kuttappu is offline Member
    Join Date
    Aug 2011
    Location
    Kerala, India
    Posts
    40
    Rep Power
    0

    Default Re: Help on how to store details from one class into an Array of another class?

    Hi, am also a java beginner. I got a small doubt to ask in your post.

    Quote Originally Posted by xxdave View Post
    I Basically want to create a member object from "Member class" and store it in the "members Array". And then create another member object untill the fixed array size is full.
    This is what i understood from your sentence, that you want your string members[] to be like:
    members[0]=obj1
    members[1]=obj2
    members[2]=obj3

    If the above result is what u want, then why not use:
    "Object[] members" instead of "String[] members"

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Help on how to store details from one class into an Array of another class?

    Please use one thread per question. The second thread you started with the same question has been closed.
    Help with Arrays please

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Help on how to store details from one class into an Array of another class?

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 19
    Last Post: 11-10-2011, 06:43 AM
  2. Showing object details of another related class
    By misbah6 in forum New To Java
    Replies: 7
    Last Post: 04-05-2010, 03:48 PM
  3. help me to store data in a class
    By neeraj.singh in forum New To Java
    Replies: 2
    Last Post: 08-06-2009, 08:31 AM
  4. Replies: 8
    Last Post: 03-21-2009, 09:34 AM
  5. Class to store Image+Text
    By Gudradain in forum New To Java
    Replies: 2
    Last Post: 11-23-2008, 08:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •