I was trying to implement encryption in my program and ran into some difficulties with methods. I have a unencrypted array, which should stay unencrypted and another array which I would like to encrypt. However, when I call the method it encrypts both arrays.
import java.util.Base64;
public class test {
    public static void main(String[] args) {
        String[] arr = {"1", "2"};
        String[] arrEncrypted = encryption(arr);
        System.out.println(arr[0]);
        System.out.println(arrEncrypted[0]);
    }
    public static String[] encryption(String[]  data) {
        for (int i = 0; i < data.length; i++) { // get each element of data
            String encodedString = Base64.getEncoder().encodeToString(data[i].getBytes()); // encryption
            data[i] = encodedString; // reassign
        }
        return data;
    }
}
I cannot find out an issue because in my understanding I return encrypted data and assign it to another array, but for some reason an array which I passed changes too.
Here is the output
MQ== //has to be 1
MQ== //correct
Thanks in advance for the help!
 
     
    