Results 1 to 7 of 7
  1. #1
    kev3kev3 is offline Member
    Join Date
    Apr 2012
    Posts
    13
    Rep Power
    0

    Default Accessing objects stored in an array list or set

    Hi,

    If someone can set me straight on this it would be much appreciated...

    Basically I have a treeSet or an ArrayList and they are storing employee objects which contain various information such as name, age, employee id, continuous service, etc.

    Once I have say 5 employees created and stored how do I then print all the information stored in the treeSet or ArrayList, by this i mean print out the information stored about each employee...?

    At the minute all i can manage to print out is some random text which i think might be the location the employees are stored..

    Thanks for any help in advance....

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,616
    Rep Power
    25

    Default Re: Accessing objects stored in an array list or set

    how do I then print all the information stored in the treeSet or ArrayList,
    Get the objects out of the container one by one and call a method in the object that will either do the printing or will return a String that is formatted for printing.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    kev3kev3 is offline Member
    Join Date
    Apr 2012
    Posts
    13
    Rep Power
    0

    Default Re: Accessing objects stored in an array list or set

    Ok, so if i was to use a toString method in my employee object. Problem I have is that the employee object is created through a number of classes so for example I have a person class which stores name, age etc. then I have a subclass manager which stores managerial information and inherits the name age etc from the person class. If i create a toString method in my manager class i don't know how to state the name, age, etc in in the toString method there.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,616
    Rep Power
    25

    Default Re: Accessing objects stored in an array list or set

    Where is the data that you want the toString() method to use to build the String it returns?
    It will have to go to where that data is located.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,120
    Rep Power
    20

    Default Re: Accessing objects stored in an array list or set

    Adding to what Norm says, if you do create a toString() method you can then just println(yourSet).
    If the output from that is not sufficient for you then you'll have to loop over the set, of course.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    kev3kev3 is offline Member
    Join Date
    Apr 2012
    Posts
    13
    Rep Power
    0

    Default Re: Accessing objects stored in an array list or set

    Thanks guys seem to have this working now, 1 small issue is that I am using blue J and the terminal window the output is printed to cuts off the start of the information as it only seems to want to display a certain amount of information and cuts off the rest is there any way to fix this so I can check that all the info printed is okay...?

  7. #7
    kev3kev3 is offline Member
    Join Date
    Apr 2012
    Posts
    13
    Rep Power
    0

    Default Re: Accessing objects stored in an array list or set

    there was an option called unlimited buffering which seems to have sorted this.

    Mega thanks for your help guys...

Similar Threads

  1. Calling methods on objects stored in an array
    By Dreaming in forum New To Java
    Replies: 6
    Last Post: 10-30-2011, 01:50 AM
  2. Storing objects in an array list?
    By Moedig in forum New To Java
    Replies: 3
    Last Post: 10-27-2011, 07:39 PM
  3. Replies: 6
    Last Post: 09-05-2011, 02:25 PM
  4. Accessing objects in array list
    By kev670 in forum New To Java
    Replies: 6
    Last Post: 03-11-2011, 01:49 AM
  5. Replies: 9
    Last Post: 02-10-2010, 04:19 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
  •