Re: Using arrays of objects ?
- From: "TideRider" <4me2know@xxxxxxxx>
- Date: Sat, 14 Apr 2007 14:50:30 GMT
I would probably use an ArrayList (from java.util). I would also define either an
interface or base class for Tool, from which all of the tools are derived, and
(using Java 5 or higher) parameterize the ArrayList:
ArrayList<Tool> toolbox = new ArrayList<Tool>();
To operate on Tool in the toolbox (again, with Java 5 or higher), you can use:
for (Tool tool : toolbox)
{
//tool variable contains the current tool
}
--
TideRider
"TonyB" <tonyb@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:E9JDh.87996$tQ1.64679@xxxxxxxxxxxxxxxxxxxxxxxxx
| I'm new to java, and would like some advice on how to keep track of groups
| of objects where the number of objects is not predefined.
| For example say I have a toolbox class which contains an arbitrary number of
| tool objects. I want to have a method to add a tool to the toolbox object,
| and other methods to list the current contents of the toolbox for example.
| I could keep a reference to each tool object as added in an array of type
| tool but an array is declared with a fixed length, so short of defining the
| array to have a some arbitrary large size I can't see how to deal with this
| list of objects. I don't want to use a database at this time.
| Is there a better way to do this ?
| Tony
|
|
.
- Follow-Ups:
- Re: Using arrays of objects ?
- From: Lew
- Re: Using arrays of objects ?
- Prev by Date: Re: newbie: popular web servers for Windows?
- Next by Date: Re: Using arrays of objects ?
- Previous by thread: Re: newbie: popular web servers for Windows?
- Next by thread: Re: Using arrays of objects ?
- Index(es):
Relevant Pages
|
|