Yes, there is a difference. As for language dependencies, some languages can make all shallow, deep, lazy copies. Some only make small copies. So yes, sometimes it depends on the language.
Now take, for example, an array:
int [] numbers = { 2, 3, 4, 5}; int [] numbersCopy = numbers;
Now the numbersCopy array contains the same values, but more importantly, the array object itself points to the same object reference as the numbers array.
So, if I did something like:
numbersCopy[2] = 0;
What will be the output for the following statements?
System.out.println(numbers[2]); System.out.println(numbersCopy[2]);
Given that both arrays point to the same link, we get:
0
0
But what if we want to make a separate copy of the first array with its own link? In this case, we would like to clone the array. In addition, each array will have its own reference to the object. Let's see how this will work.
int [] numbers = { 2, 3, 4, 5}; int [] numbersClone = (int[])numbers.clone();
Now the numbersClone array contains the same values, but in this case the array object itself indicates a different reference than the numbers array.
So, if I did something like:
numbersClone[2] = 0;
What will be the output for the following statements?
System.out.println(numbers[2]); System.out.println(numbersClone[2]);
You guessed it:
four
0
Source