I have two String arrays, let’s say:
String[] s1 = {"a","b","c"}
String[] s2 = {"c","a","b"}
//these arrays should be equal
I wanted to check their equality in the “cleanest” way.
I tried using Arrays.equals(s1,s2) but I’m getting a false answer. I guess that this method cares about the elements’ order and I don’t want that to matter.
Can you please tell me how can I do that in a nice way?
In case you do not want to modify the original arrays
Arrays.sort() uses an optimized quick sort which is nlog(n) for average but O(n2) in worst case. From the java docs. So the worst case it will O(n2) but practically it will be O(nlogn) for most of the cases.