Dynamic array creation
3 Message(s) by 3 Author(s) originally posted in java misc
| From: None |
Date: Thursday, June 01, 2006
|
Dynamic
array creation
Hi all... here's a good one for you...
I've a situation where I've some
bean , and I need to populate an
array
field in it... here's the problem... I don't know the element
type of the array before runtime.
Now, I have been planning on using Commons Beanutils, since the rest of
this particular
app does (it's doing a lot of introspection of the
beans and such).
So, here's the question... can anyone figure out a way to dynamically
create an array at runtime? What I mean is, I want to do the
followig:
PropertyUtils.setProperty(obj, fieldName,
((List)fieldValues).toArray());
So, I want to set the field
named by fieldName on the bean instance
referenced by obj, and I want to do it by taking the fieldValues List
and converting it to an array. Now, I can do:
PropertyUtils.setProperty(obj, fieldName,
((List)fieldValues).toArray(new String[0]));
...and that's great, except that I do not know until runtime that the
field of the bean is of type String, it could be anything else. So,
how can I dynamically do the equivalent of the new String[0] is really
the question?
FYI, I do not really care if this is done with Beanutils, but I think
that's probably the
logical course of action. Any ideas? Thanks all!
| From: Oliver Wong |
Date: Friday, June 02, 2006
|
| From: CV |
Date: Friday, June 16, 2006
|
wrote in message:
Dynamic array creation
Hi all... here's a good one for you...
I've a situation where I've some bean, and I need to populate an
array field in it... here's the problem... I don't know the element
type of the array before runtime.
Can't you use a
class from the Collection
framework instead of an array?
An ArrayList
object for example.C
Next Message: JAVA HelpSet
Blogs related to Dynamic array creation
Java, JavaScript and Jython
Feature,
Java, JavaScript, Jython. Type System, Static with few
dynamic checks
... An object is an associative
array - with keys being either string or integer.
... Object
Creation, Person p = new Person();, var p = new Person();
...
Tapestry Support Network Launched
July 26, 2005 – Open source
Java development efforts were boosted today with news of a
... announced today the
creation of the Tapestry Support Network (TSN).
... Tapestry 4.0 offers an
array of new and advanced features for Tapestry
...
JavaScript Tutorial
One to hold the HTML for a line break and the other was a
dynamic ... Javascript
Array Object - General information about the Javascript
Array Object.
... Want to dish out some pain of your own
creation onto unsuspecting visitors?
...
Six Design Patterns to Start With
An easy and common example is the
creation of a data access layer to support
... of an
array of command patterns that have some sort of DoOperations(connection,
... Learning about Design Patterns;
Dynamic Behavior with the Decorator
...
HTTP ebooks(2)
0423: When Goliaths Clash Managing Executive Conflict To Build A More
Dynamic Organization 0424: Translating Strategy Into Shareholder Value A Company Wide Approach To Value
Creation 0425: The Supply Chain Imperative How to Ensure
...
Java FAQ
creation time, depending on which constructor is used.
... DLL stands for
Dynamic Linking Library and has definite structure inside. DLL is a part of executable
... array. You may need to // pass the values through
java.net.URLEncoder.
...