Refactored array comparison (Java)