Comparing arrays that have same elements in different order

前端 未结 6 955
遥遥无期
遥遥无期 2020-12-17 21:26

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};
6条回答
  •  心在旅途
    2020-12-17 21:45

    You are reinventing wheel to sort arrays.

    Use

    java.util.Arrays.sort(T[] a, Comparator c)
    

    also there are methods to sort primitive types such as int.

提交回复
热议问题