Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dynamically setting Object data

 
William Davis
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic