views:

26

answers:

2
+4  A: 

Arrays are objects, not primitives. Using == on objects only compares if they both points to the same reference, while you actually want to compare every individual array item separately.

You want to use Arrays#equals() for this.

if (Arrays.equals(methodParams, searchParams)) {
    // ...
}
BalusC
Works, fantastic.
Sticky
You're welcome.
BalusC
+1  A: 

Your first method is not actually comparing the array elements, it's comparing the array references, which won't be the same. If you think the second piece of code is ugly, you might want to look at Arrays.equals(Object[] a, Object[] a2), which will actually compare two arrays in a pairwise fashion (exactly what you're doing in the second case).

jasonmp85