aspose file tools*
The moose likes Beginning Java and the fly likes append objects to array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "append objects to array" Watch "append objects to array" New topic
Author

append objects to array

gon to
Greenhorn

Joined: Jan 20, 2006
Posts: 18
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

Joined: Sep 20, 2003
Posts: 1704
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

Joined: Sep 28, 2004
Posts: 18978
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
gon to
Greenhorn

Joined: Jan 20, 2006
Posts: 18
thats it, thanks very much!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: append objects to array