Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > dynamic arrays

Reply
Thread Tools

dynamic arrays

 
 
segex
Guest
Posts: n/a
 
      08-25-2005
Hi all

I was wondering if it is possible to make an array dynamicly. I don't
the easy newbie stuff like
-----
int[] meth(int size) {
return new int[size];
}
-----
I actually more though of making an array of whatever (primitiv-type or
class and all sorts of dimensions)
so more somthing like:
-----
/*
* Signature is something similar to
* [I for int[] or
* [[Ljava.lang.String for String[][]
* etc
*/
Object makeArr(String signature) {
return <made array>
}
-----

G. Segex

 
Reply With Quote
 
 
 
 
freesoft_2000
Guest
Posts: n/a
 
      08-25-2005
Hi everyone,

You can use the Java ArrayList class

Richard West

 
Reply With Quote
 
 
 
 
Thomas Hawtin
Guest
Posts: n/a
 
      08-25-2005
segex wrote:
>
> /*
> * Signature is something similar to
> * [I for int[] or
> * [[Ljava.lang.String for String[][]
> * etc
> */
> Object makeArr(String signature) {
> return <made array>
> }


java.lang.reflect.Array.newInstance(Class<?>,int)

Typical implementations of Collection.toArray(Object[]) use it.

Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
 
Reply With Quote
 
Thomas G. Marshall
Guest
Posts: n/a
 
      08-26-2005
freesoft_2000 coughed up:
> Hi everyone,
>
> You can use the Java ArrayList class
>
> Richard West



Have you lost your @#$%ing mind, or did you simply not read his post?


 
Reply With Quote
 
segex
Guest
Posts: n/a
 
      08-26-2005
Oh, didn't think it was that simple

well thanks a lot

 
Reply With Quote
 
Raymond DeCampo
Guest
Posts: n/a
 
      08-26-2005
Thomas G. Marshall wrote:
> freesoft_2000 coughed up:
>
>>Hi everyone,
>>
>> You can use the Java ArrayList class
>>
>>Richard West

>
>
>
> Have you lost your @#$%ing mind, or did you simply not read his post?
>
>


I thought he was just giving people permission to use the ArrayList
class. After all, he didn't quote anybody, so who knows? And he did
address the post to everybody, not just the OP.

So now we can rest easy knowing that Richard West is allowing us to use
the ArrayList class. The one I'm sweating out is HashMap....

Ray

--
XML is the programmer's duct tape.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      08-28-2005
On Thu, 25 Aug 2005 15:57:51 +0100, Thomas Hawtin
<(E-Mail Removed)> wrote or quoted :

>
>java.lang.reflect.Array.newInstance(Class<?>,in t)


the other way to do it without reflection would be a switch on
dimension to create 1 to 10 dimensions

e.g.

case 3:
return new Qbject[a0][a1][a2];
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
 
Reply With Quote
 
Thomas Hawtin
Guest
Posts: n/a
 
      08-28-2005
Roedy Green wrote:
> On Thu, 25 Aug 2005 15:57:51 +0100, Thomas Hawtin
> <(E-Mail Removed)> wrote or quoted :
>
>
>>java.lang.reflect.Array.newInstance(Class<?>,int )

^length
>
>
> the other way to do it without reflection would be a switch on
> dimension to create 1 to 10 dimensions
>
> e.g.
>
> case 3:
> return new Qbject[a0][a1][a2];


A different issue. I believe G. Segex was primarily looking at creating
arrays of different types rather than dimensions. You can't switch on
all possible types ever.

To create an array (of arrays)^n use:

java.lang.reflect.Array.newInstance(Class<?>,int[] dimensions)

Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multidimensional arrays and arrays of arrays Philipp Java 21 01-20-2009 08:33 AM
char arrays and integer arrays... why the difference? Bill Reyn C++ 3 06-22-2004 12:01 PM
Arrays.asList() returning java.util.Arrays$ArrayList Alexandra Stehman Java 5 06-17-2004 06:04 PM
Arrays and Pointers to Arrays kelvSYC C Programming 2 09-26-2003 06:52 AM
initializing arrays of arrays Mantorok Redgormor C Programming 4 09-11-2003 02:08 AM



Advertisments