Java Array Comparison
- by BlairHippo
Working within Java, let's say I have two objects that, thanks to obj.getClass().isArray(), I know are both arrays. Let's further say that I want to compare those two arrays to each other -- possibly by using Arrays.equals. Is there a graceful way to do this without resorting to a big exhaustive if/else tree to figure out which flavor of Arrays.equals needs to be used? I'm looking for something that's less of an eyesore than this:
if (obj1 instanceof byte[] && obj2 instanceof byte[]) {
return Arrays.equals((byte[])obj1, (byte[])obj2);
}
else if (obj1 instanceof boolean[] && obj2 instanceof boolean[]) {
...