Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2003

Tip: Looking for answers? Try searching our database.

How to create an array from a Class?

Thread view: 
Joona I Palaste - 30 Sep 2003 13:12 GMT
Suppose I have a Java Class object denoting some Java class. I would
like to dynamically create an *array* of references to the class that
the Class object denotes. The size of the array should also be given in
the creation. What is the easiest way of doing this?

Example of what I have in mind:

Class c = "Hello, world!".getClass();
String[] array = /* what the heck do I write here? */;
array[0] = "Hello, world!";
for (int i=0; i<array.length; i++) {
 System.out.println(array[i]);
}

Should print "Hello, world!");

Signature

/-- Joona Palaste (palaste@cc.helsinki.fi) ---------------------------\

| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste       W++ B OP+                     |
\----------------------------------------- Finland rules! ------------/
"The truth is out there, man! Way out there!"
  - Professor Ashfield
David Zimmerman - 30 Sep 2003 13:16 GMT
> Suppose I have a Java Class object denoting some Java class. I would
> like to dynamically create an *array* of references to the class that
[quoted text clipped - 11 lines]
>
> Should print "Hello, world!");

Array.newInstance(Class, int)
Joona I Palaste - 30 Sep 2003 13:23 GMT
David Zimmerman <dzimm@hiddenmind.com> scribbled the following:
>> Suppose I have a Java Class object denoting some Java class. I would
>> like to dynamically create an *array* of references to the class that
>> the Class object denotes. The size of the array should also be given in
>> the creation. What is the easiest way of doing this?

> Array.newInstance(Class, int)

Thanks!

Signature

/-- Joona Palaste (palaste@cc.helsinki.fi) ---------------------------\

| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste       W++ B OP+                     |
\----------------------------------------- Finland rules! ------------/
"The obvious mathematical breakthrough would be development of an easy way to
factor large prime numbers."  
  - Bill Gates


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.