Possible Duplicate:
Java: Checking equality of arrays (order doesnt matter)
I have two arrays :
String[] a1 = {"a", "b", "c"};
String[] a2 = {"c", "b", "a"};
I need to check if both contains same elements (and of same length) irrespective of order of elements.
I tried Arrays.equals(a1, a2)
but it considers order of element.
org.apache.commons.lang.ArrayUtils
does not provide this thing.
I know I can achieve the same by creating my own method (checking for same length, then sorting both array and then using Arrays.equals(a1, a2)
) but wanted to know if this thing is provided in any API or there is more smart way to do the same.