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
Post a Comment