I wrote below code to compare to arrays that have same elements but in diff order.
Integer arr1[] = {1,4,6,7,2}; Integer arr2[] = {1,2,7,4,6};
You are reinventing wheel to sort arrays.
Use
java.util.Arrays.sort(T[] a, Comparator super T> c)
also there are methods to sort primitive types such as int.