Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

append objects to array

 
gon to
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
i got an array question. i'd like to create a new array and append nodes to it in a loop, like this:

 
Kj Reddy
Ranch Hand
Posts: 1704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can add the following line below inside the loop:

allChildren[index] = aNode;

You need to give integer value for index.
 
Henry Wong
author
Marshal
Pie
Posts: 20889
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arrays don't keep track of the last used members -- so it doesn't have a concept of append. You can set any member as such...

allChildren[some_index] = anode;

You have two options. You can keep track of the last used location yourself, or you can use one of the collections classes that does do it -- such as ArrayList or Vector.

Henry
 
gon to
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thats it, thanks very much!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic