I am new at Java and I am trying to sort a list called rojas who has been copied from list. When using arrays.sort and then printing it, I realized that both rojas and list are getting sorted.
public static void main(String[] args) {
int[] list = {611, 700, 777, 901, 4124, 8000, 9014, 6213113, 15, 19, 100, 102, 150, 177, 310, 330, 400, 590, 600};
int[] rojas = list;
int size = 20;
int value = 100;
for (int i=0 ;i< size-1; i++){
if(list[i] == value){
System.out.println("Element found index is :"+ i);
break;
}
else{
System.out.println("Element not found");}
}
Arrays.sort(rojas);
System.out.println("element found by binary search is in index: " + Arrays.binarySearch(rojas,100));
System.out.println(Arrays.toString(rojas));
System.out.println(Arrays.toString(list));
}