I have a table with 4 array columns.. the results are like:
ids signed_ids new_ids new_ids_signed {1,2,3} | {2,1,3} | {4,5,6} | {6,5,4}
Anyway to compare ids
and signed_ids
so that they come out equal, by ignoring the order of the elements?
Check if two arrays are equal or not using Sorting Follow the steps below to solve the problem using this approach: Sort both the arrays. Then linearly compare elements of both the arrays. If all are equal then return true, else return false.
We can use the logic below to compare the equality of two lists using the assertTrue and assertFalse methods. In this first test, the size of both lists is compared before we check if the elements in both lists are the same. As both of these conditions return true, our test will pass.
Using Arrays. equals(array1, array2) methods − This method iterates over each value of an array and compare using equals method. Using Arrays. deepEquals(array1, array2) methods − This method iterates over each value of an array and deep compare using any overridden equals method.
Java: Checking equality of arrays (order doesn't matter)
You can use contained by operator:
(array1 <@ array2 and array1 @> array2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With