Object -> Object[]
Author |
Message |
Zren
![](http://compsci.ca/v3/uploads/user_avatars/1110053965512db6185954b.png)
|
Posted: 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 );
}
|
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Generic
|
Posted: 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". |
|
|
|
|
![](images/spacer.gif) |
|
|