Hi I want to copy an array...and I do not want to use \"clone\" which is slow to copy.. I tried arraycopy and copyOf, but it is not working
for (int i = 0; i <
The real issue is that you store references in the array. If you want the objects in the new array to be independent of the objects in the original array, you have to make a deep copy. For that, cities[i].clone()
is your friend.
As to your performance issue, it could well be due to the fact that you copy the array during every iteration of the loop. This is very wasteful; a single copy would suffice.