Article View: borland.public.jbuilder.java.language
Article #18847Re: arrays of objects
From: John C. Sinues
Date: Wed, 08 Apr 1998 00:00
Date: Wed, 08 Apr 1998 00:00
49 lines
2349 bytes
2349 bytes
It sound likes you could use a Hashtable (java.util.Hashtable) which
is like a lookup array. Visually, your data structure would look
something like this:
Hashtable: myObject2
key1->myObjects1, myObjects2
key2->myObjects3, myObjects4, myObjects5
key3->myObjects6
key4->myObjects7, myObjects8
"myObject2" would be defined as a hashtable with its keys (key1, key2,
key3, and key4) being the "pointers" to the objects defined in your
myObjects2 array. The data in your myObjects array are the lookup
value(s) for the keys.
Hope this helps.
Kevin B wrote:
> Hi,
>
> I'm a C++/Delphi programmer that is fairly new to Java and I'm trying to
> makes some sense of something that is easy in either of these languages but
> not so intuitive in Java (to me).
>
> I'd like to be able to create a couple arrays of objects in Java and I'd
> like to preallocate the arrays so that I don't have the performance problem
> of creating each object separately. This is no problem as I can just do
> something like...
>
> MyObjectType myObjects[] = new MyObjectType[ 10000 ];
>
> But what I'd like to do is create another array that will only hold a
> subset of the elements from this array. Since the object that makes up
> each element of this array is fairly large, I'd like for the elements of
> the second array to just be able to POINT at the actual objecs of the first
> array.
>
> This is easy in C++ or Delphi as I can just make the second array be an
> array of pointers (of type MyObjectType) and do something like
>
> myObjects2[i] = &myObjects[j];
>
> But since there are no pointers in Java I'm confused as to how to do this
> or whether this is even possible. Can somebody straigten me out on this?
>
> TIA!!
>
> Kevin
Technical Details
Message-ID:
<352B3794.CA9396DD@prc.prc.mrms.navy.mil>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<01bd62ec$0c857a40$b2c33081@boylankl>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,d90257f1ce51c897 X-Google-Attributes: gidf74b3,public From: "John C. Sinues" <sinues@prc.prc.mrms.navy.mil> Subject: Re: arrays of objects Date: 1998/04/08 Message-ID: <352B3794.CA9396DD@prc.prc.mrms.navy.mil> X-Deja-AN: 342058212 Content-Transfer-Encoding: 7bit References: <01bd62ec$0c857a40$b2c33081@boylankl> Content-Type: text/plain; charset=us-ascii Organization: Another Netscape Collabra Server User Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language