Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Object -> Object[]
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Zren




PostPosted: Fri Oct 01, 2010 11:34 pm   Post subject: Object -> Object[]

How would I test, and then convert a Object into an array of Objects?

Edit: Ha hah! I figured it out. Any better solutions?

Java:

Class classType = obj.getClass().getComponentType();
if (classType != null) { // Is this an Array of objects?
     Object[] objs = new Object[Array.getLength(obj)];
     for (int i = 0; i < Array.getLength(obj); i++)
         objs[i] = Array.get(obj, i);
}
Sponsor
Sponsor
Sponsor
sponsor
Generic




PostPosted: Sun Oct 03, 2010 9:18 pm   Post subject: RE:Object -> Object[]

Object obj = new Object();
Object[] arr = {obj};
Creates a new Object then initialize an array with one element "obj".
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: