aspose file tools*
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
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Dynamically setting Object data