If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

multiple datatype array, how can I create one?

I want to create an array element that store multiple data types, for example
I'm using Object[] mult_type = new Object[4];
How can I go about to do that in storing different type of objects and retrieve
the objects back into it's original states?

Re: multiple datatype array, how can I create one?

First, you can only store Objects in an array of Objects. This means
everything except the primitive types (int, char, boolean, etc.); if you
want to store them you have to wrap them in their corresponding Object
Wrapper classes (Integer, Character, Boolean, etc.) So for your examples:

and so on. Although mult_type[i] is an Object by definition, the entry
stored there can be any subclass of Object. When you want to retrieve them,
you can examine them to find out what class they actually belong to. There
are a couple of ways to do this, one is to use the "instanceof" operator
like so:

Notice that you have to "cast" the object to its actual class as you
retrieve it.

PC2

Ming <ming.fang@sungard> wrote in message news:39ecb84a$1@news.devx.com...
>
> I want to create an array element that store multiple data types, for
example
> I'm using Object[] mult_type = new Object[4];
> How can I go about to do that in storing different type of objects and
retrieve
> the objects back into it's original states?
>
>
> data type index
> --------------------
> String 0
> int 1
> long 2
> short 3
> ....... ..