This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
Looks like a great opportunity for a tiny custom class.
Now you can do something like
Now I finally got to your question with "collection". As a generic term it means a holder for a bunch of things. I loved the name "bag" in SmallTalk. In Java Collection is an interface with a number of cool implementations. Look at the JavaDoc for Collection, List, ArrayList and see if you find something you like. You can return any of the concrete implementations from your method.
I'm also leaving for you to puzzle out how the calling method gets your things out of the collection and uses them. Write again if you need some hints there.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Joined: Nov 11, 2004
Thanks for your post, I had already implemented my custom classes which hold the data that is processed from the file, this is working fine.
My primary concern atm is I want to make the file processing and object instantiation code more efficent.
At the moment one of my classes reads the file and passes each line seperately to the class which creates the objects. I presumed (maybe incorrectly) that it would be more efficent to read the file and add each line (hopefully pre-tokenized) into a collection which could then be passed as a complete collection to the object instantiating class.
Is this not a good way of doing it?
Joined: Jan 29, 2003
I wouldn't worry too much about the efficiency; either way will be fine. If we were going to have readers for multiple sources that generate the same little objects - flat file, properties file, XML parser, database, remote procedure call, etc - then I'd spend some time studying the responsibilities and avoiding duplicate code in all the readers. But don't try to solve that problem until it happens.