java - Copying array contents to a new array -


i trying write method called reallocate, takes array called thedirectory, , copies it's contents on new array named newdirectory, has twice capacity. thedirectory set newdirectory.

this have far, stuck on how copy content across newdirectory, appreciated.

private void reallocate()    {        capacity = capacity * 2;        directoryentry[] newdirectory = new directoryentry[capacity];        //copy contents of thedirectory newdirectory        thedirectory = newdirectory;     } 

thanks in advance.

you can use system.arraycopy that.

api here.

simple example destination array double capacity:

int[] first = {1,2,3}; int[] second = {4,5,6,0,0,0}; system.arraycopy(first, 0, second, first.length, first.length); system.out.println(arrays.tostring(second)); 

output

[4, 5, 6, 1, 2, 3] 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -