Easier way to find matching array from a lot of arrays I have the following arrays which save the MAC-adresses of a lot of bluetooth beacons and their positions in a building:

private static final String[][] MAC_ADDRESSES_A_BLUETOOTH = {{"B09122F5D126", "210.105"}, {"B09122F5F26B", "136.121"}, {"B09122F5F619", "181.172"}};
...
private static final String[][] MAC_ADDRESSES_Q_BLUETOOTH = {{"B09122F5D124", "210.105"}, {"B09122F5F26Z", "136.121"}, {"B09122F5F61Q", "181.172"}};


Then I'm looking for the matching triple based on a current triple:

private String[][] compareArrays(String[] beacon) {
        if (Arrays.equals(beacon, getFirstArray(MAC_ADDRESSES_A_BLUETOOTH))) {
            return MAC_ADDRESSES_A_BLUETOOTH;
        } else if (Arrays.equals(beacon, getFirstArray(MAC_ADDRESSES_B_BLUETOOTH))) {
            return MAC_ADDRESSES_B_BLUETOOTH;
        } else if (Arrays.equals(beacon, getFirstArray(MAC_ADDRESSES_C_BLUETOOTH))) {
            return MAC_ADDRESSES_C_BLUETOOTH;
        } else if (Arrays.equals(beacon, getFirstArray(MAC_ADDRESSES_D_BLUETOOTH))) {
            return MAC_ADDRESSES_D_BLUETOOTH;
        } else if (Arrays.equals(beacon, getFirstArray(MAC_ADDRESSES_F_BLUETOOTH))) {
            return MAC_ADDRESSES_F_BLUETOOTH;
        } else if (Arrays.equals(beacon, getFirstArray(MAC_ADDRESSES_G_BLUETOOTH))) {
            return MAC_ADDRESSES_G_BLUETOOTH;
        } else if (Arrays.equals(beacon, getFirstArray(MAC_ADDRESSES_H_BLUETOOTH))) {
            return MAC_ADDRESSES_H_BLUETOOTH;
        } else if (Arrays.equals(beacon, getFirstArray(MAC_ADDRESSES_I_BLUETOOTH))) {
            return MAC_ADDRESSES_I_BLUETOOTH;
        } ...
        } else {
            return null;
        }
}


This code looks horrible and it bugs me. Is there an easier way to do this without having to write 16 if statements? getFirstArray returns all first values from a two-dimensional array.
For readability, use an Object instead of a 2d array.

E.G:

public class BluetoothMacAddress {
    private String macAddress;
    private float positionInBuilding;
}


Use java.util.List, then you can have a list of lists:

private sttaic final List&lt;MacAddress&gt; MAC_ADDRESSES_A_BLUETOOTH = Arrays.asList(
    new BluetoothMacAddress("B09122F5D126", "210.105"),  
    new BluetoothMacAddress("B09122F5F26B", "136.121"), 
    new BluetoothMacAddress("B09122F5F619", "181.172"));

private static final List&lt;List&lt;MAC_ADDRESSES&gt;&gt; MAC_ADDRESSES = Arrays.asList(
    MAC_ADDRESSES_A_BLUETOOTH,
    MAC_ADDRESSES_B_BLUETOOTH 
    ...
);


Your new method would then look something like this:

private MacAddress compareArrays(String[] beacon) {
    for (List&lt;MacAddress&gt; macAddresses : MAC_ADDRESSES ) {
        if (Arrays.equals(beacon, getFirstArray(macAddresses))) {
            return macAddresses;
        }
    }
    // not found
    return null;
}


You'd have to change the beacon parameter to be a MacAddress too, or convert the MacAddress to a String[] (or visa-versa).