Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

append objects to array  RSS feed

 
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
Sheriff
Posts: 23283
125
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!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!