I don't know the type of arrays the OP is using, but it might be better to set the two arrays to be equal after the for loop, rather than doing it every time you add something.