Let's start with the code:
File file2 = new File(); file2 = LoadedFiles[2];
The first line is redundant. You select a new file, just to say “hey look, forget about it, take that one from the array”. Well, do not create a new file, and then:
File file2 = LoadedFiles[2];
Now it looks like you copied everything that is in LoadFiles [2]. But you didn’t. All that you copied was a reference to this object. There is still only one object, and now two variables know about it.
For comparison: Your friend lives on Oak Street, 123. You have this address in your address book. This is a link. You don’t have his real house, just a link to his house so you can find him. When you copy this link by sending it to another friends phone book, the link has been copied. The original house is still the only house. After copying the address, there was no second home.
source share