Results 1 to 3 of 3
  1. #1
    orushw is offline Member
    Join Date
    May 2011
    Posts
    8
    Rep Power
    0

    Default Want to know something about lists.

    Hi,
    I have 2 classes in my program.
    1 class named people and it has 2 variables : int age and String name.
    The second class is PeopleArray that contain list of people class :
    This is what i have at the PeopleArray class :
    ArrayList PArray = new ArrayList();
    People p = new People();
    PArray.add(p);
    Now i want to access the name of one people :
    String name = p.name;
    But i cant do it, how can i do it by the list? (i dont want to use arrays because i dont know what will be the array size).
    I`ll be happy if someone can help me.
    Thanks,
    Or.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,560
    Blog Entries
    7
    Rep Power
    21

    Default Re: Want to know something about lists.

    Don't use a 'raw' list, use a generic list instead:

    Java Code:
    List<People> pArray= new ArrayList<People>();
    Now the compiler 'knows' that pArray contains People objects and you can do pArray.get(0).name.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    orushw is offline Member
    Join Date
    May 2011
    Posts
    8
    Rep Power
    0

    Default Re: Want to know something about lists.

    Thanks !
    You helped me alot.

Similar Threads

  1. Array Lists help!!
    By lilika in forum New To Java
    Replies: 12
    Last Post: 01-04-2011, 02:05 PM
  2. Help with lists
    By datreta in forum New To Java
    Replies: 6
    Last Post: 10-29-2010, 11:33 AM
  3. Stacks, lists...
    By little_polarbear in forum New To Java
    Replies: 7
    Last Post: 08-02-2008, 01:59 PM
  4. comparision between two lists
    By suprabha in forum Advanced Java
    Replies: 14
    Last Post: 08-01-2008, 02:49 PM
  5. Tudu Lists 2.0
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 07-11-2007, 03:32 PM

Posting Permissions

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