Results 1 to 7 of 7
- 04-24-2012, 06:27 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 13
- Rep Power
- 0
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....
- 04-24-2012, 06:32 PM #2
Re: Accessing objects stored in an array list or set
how do I then print all the information stored in the treeSet or ArrayList,If you don't understand my response, don't ignore it, ask a question.
- 04-24-2012, 06:35 PM #3
Member
- Join Date
- Apr 2012
- Posts
- 13
- Rep Power
- 0
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.
- 04-24-2012, 06:44 PM #4
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.
- 04-24-2012, 06:59 PM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
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 **
- 04-24-2012, 07:08 PM #6
Member
- Join Date
- Apr 2012
- Posts
- 13
- Rep Power
- 0
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...?
- 04-24-2012, 07:10 PM #7
Member
- Join Date
- Apr 2012
- Posts
- 13
- Rep Power
- 0
Similar Threads
-
Calling methods on objects stored in an array
By Dreaming in forum New To JavaReplies: 6Last Post: 10-30-2011, 01:50 AM -
Storing objects in an array list?
By Moedig in forum New To JavaReplies: 3Last Post: 10-27-2011, 07:39 PM -
Performance issue adding and removing lots of objects to Array list, need better way.
By Neilos in forum New To JavaReplies: 6Last Post: 09-05-2011, 02:25 PM -
Accessing objects in array list
By kev670 in forum New To JavaReplies: 6Last Post: 03-11-2011, 01:49 AM -
arraylist help please? trying to add objects to an array list
By zhangster in forum New To JavaReplies: 9Last Post: 02-10-2010, 04:19 AM
Bookmarks