I've tried doing it many ways however if I make any changes to one copy, those changes are reflect in the other. I've also tried to deep copy with no results please help.
My deep copy method:
public static ArrayList<Integer> cloneList(ArrayList<Integer> list) {
ArrayList<Integer> clone = new ArrayList<Integer>(list.size());
for (int i=0;i<list.size();i++){
clone.add(list.get(i));
}
return clone;
}
Small Change: this is the method used when making a change to the copied arraylist
public static ArrayList<Integer>smallChange(ArrayList<Integer>oldArray){
int firstNo;
int secondNo;
do{
Random rand1 = new Random();
Random rand2 = new Random();
firstNo = (int) Math.abs(matrix_length*rand1.nextDouble());
System.out.println("A: "+firstNo);
secondNo = (int) Math.abs(matrix_length*rand2.nextDouble());
System.out.println("B: "+secondNo);
}while(firstNo == secondNo);
int temp1 = oldArray.indexOf(firstNo);
int temp2 = oldArray.indexOf(secondNo);
oldArray.set(temp1, secondNo);
oldArray.set(temp2,firstNo);
ArrayList<Integer> newArrayList = oldArray;
return newArrayList;
}