Meaningless Drivel is fun!
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

Dynamically setting Object data

William Davis

Joined: May 30, 2001
Posts: 1
I can set the value of an Object in my code as follows:
Object abc = { "one", "two", "three" };
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.
I agree. Here's the link:
subject: Dynamically setting Object data
It's not a secret anymore!