This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes Dynamically setting Object data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Dynamically setting Object data" Watch "Dynamically setting Object data" New topic
Author

Dynamically setting Object data

William Davis
Greenhorn

Joined: May 30, 2001
Posts: 1
I can set the value of an Object in my code as follows:
<CODE>
Object abc = { "one", "two", "three" };
</CODE>
How can I change the value programmatically, i.e., what if I want to add the value "four" at runtime?
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi William,
Bottom line is you can't. Once a java array is declared and initialized its' size can NOT be changed.
That is the reason why Vectors were created. Also you can look into ArrayList.
In your case abc will never point to more than three items! However you can change any of the three items any time you want.
Regards,
Manfred.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dynamically setting Object data