Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

appending to an array????

Status
Not open for further replies.

sribu

Programmer
Mar 8, 2003
17
US
Can anyone tell me how can we append data to an existing array in java?

thanks
 
If you are referring to appending data beyond the current end of the allocated array, you can’t do that in any language since the memory does not exist for you to write in. You have to use whatever mechanism exists in the given language to allocate the additional memory first. At the lowest levels this would result in the following:

1) Allocate new memory equaling the size of the existing block plus the additional space required
2) Copy the original data into the new memory location

Now you can append more elements (write data) into the additional memory space allocated.

In Java to copy arrays use the java.lang.System.arraycopy() function.

-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top