Re: Using arrays of objects ?



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
|
|


.



Relevant Pages

  • Re: another Java 101 question
    ... If I look on the as/400, according to "Java at Work" the toolbox that came ... I see a some .jar files (jt400.jar jt400proxy.jar ... ListCustomers.java:25: Class AS400 not found in type declaration. ...
    (comp.sys.ibm.as400.misc)
  • Re: Using arrays of objects ?
    ... For example say I have a toolbox class which contains an arbitrary ... number of tool objects. ... added in an array of type tool but an array is declared with a fixed ...
    (comp.lang.java)
  • Re: logistic regression - the ordinal function
    ... I am a matlab newbie and want to perform logistic regression with ... I'm going to assume that you've got the Statistics Toolbox. ... The ORDINAL function creates a data array of ordinal values -- discrete, ordered data. ... To do logistic regression, you'll want 'binomial', and you can also specify the link function. ...
    (comp.soft-sys.matlab)
  • Re: Input into Net::Netmask
    ... Your "@blocks" array contains two elements, ... Perl isn't a toolbox, but a small machine shop where you can special-order ...
    (comp.lang.perl.misc)
  • Suppress toolbox icon
    ... my dll, it initially selects all of the control classes in my dll. ... some attribute that I can attach to my class declaration to tell the Toolbox ... I don't want the base class to be available to ...
    (microsoft.public.dotnet.framework.windowsforms.controls)