Q:

How to store pairs in Java?

I'm writing a small API program in Java, that will validate IP addresses. In the simplest iteration (1.2.3.4) I just call a library like googles guava and get a true or false.
The problem I have is that the input can contain ip ranges, i.e. 192-198.10.12.16-20/24
Since guava won't validate this kind of input as a valid IP address I'm trying to process the IP address before calling guava.
I thought I would do the following:

Cut off the network mask (here /24) if any.
Use the split("\.") method to separate the octets into an array(?) of Strings.
Extract the IP range of an octet into a separate array of Strings, so the array of octets contains only the main IP address, that I can now pass to guava for validation.
As last step I'd check if a given IP range is greater the octet it belongs to and smaller 256. If yes, the then the original IP address (see above) is fine.

As explained I need a data type that will allow me to store the original relationship between the octets of the main IP address and IP range of an octet (if any) in order to perform the check described in 4 and to restore the original IP address notation, i.e. be able to concatenate the octets and the ip ranges.
To visualize the above I need:
Octet 1 (192), IP Range 1 (198)
Octet 2 (10), IP Range 2 ()
Octet 3 (12), IP Range 3()
Octet 4 (16), IP Range 4 (20)

Will a array like String [][] octets do this job? If yes, how would I fill it? If not, what other data type would fit here?

A:

Bill K has right. And here is a simple example class:
    public class IPAddress {

        private IPOctet octet1;
        private IPOctet octet2;
        private IPOctet octet3;
        private IPOctet octet4;

        private static final String NETWORK_MASK_CHAR = "/24";

        public IPAddress(String value) throws Exception{
            value = cutOffNetworkMask(value);
            String[] octets = value.split("\\.");
            if (octets.length < 4) throw new Exception("Invalid input value. Too few octets.");
            octet1 = new IPOctet(octets[0]);
            octet2 = new IPOctet(octets[1]);
            octet3 = new IPOctet(octets[2]);
            octet4 = new IPOctet(octets[3]);
        }

        public boolean hasMatchOf(IPAddress another){
            if (!octet1.isMatching(another.getOctet1())) return false;
            if (!octet2.isMatching(another.getOctet2())) return false;
            if (!octet3.isMatching(another.getOctet3())) return false;
            if (!octet4.isMatching(another.getOctet4())) return false;
            return true;
        }

        public IPOctet getOctet1(){ return octet1; }
        public IPOctet getOctet2(){ return octet2; }
        public IPOctet getOctet3(){ return octet3; }
        public IPOctet getOctet4(){ return octet4; }

        private static String cutOffNetworkMask(String base){
            int index = base.indexOf(NETWORK_MASK_CHAR);
            try{
                if (index > -1) base = base.substring(0, index);
            }catch(IndexOutOfBoundsException ignored){}
            return base;
        }

    }

The IPOctet class:
    public class IPOctet {

        private static final String RANGE_SYMBOL = "-";
        int max = 255;
        int min = 0;

        public IPOctet(String stringValue) throws Exception {
            int index = stringValue.indexOf(RANGE_SYMBOL);
            if (index < 0){
                // This octet is a single byte;
                max = str2int(stringValue);
                min = max;
            }else{
                // This octet has a range.
                String[] values = stringValue.split(RANGE_SYMBOL);
                if (values.length != 2) throw new Exception("Invalid Input. Range must be like xx-xx");
                min = str2int(values[0]);
                max = str2int(values[1]);
            }
        }

        public boolean isMatching(IPOctet another) {
            if (max < another.getMinValue()) return false;
            if (min > another.getMaxValue()) return false;
            return true;
        }

        public int getMinValue(){ return min; }
        public int getMaxValue(){ return min; }

        private static int str2int(String input) throws Exception{
            int result;
            try{
                result = Integer.parseInt(input);
            }catch(NumberFormatException nfe){
                throw new Exception("Invalid input. Input is not a number.");
            }
            validate(result);
            return result;
        }

        private static void validate(int input) throws Exception{
            if (input < 0 || input > 255) throw new Exception("Invalid input. Must be between 0 and 255");
        }

    }

And here a simple test case:
    public class Main {

        public static void main(String[] args){
            try{
                IPAddress adr1 = new IPAddress("192.168.1.0-255");
                IPAddress adr2 = new IPAddress("192.168.1.1/24");
                IPAddress adr3 = new IPAddress("1.2.3.4");
                System.out.println("adr2 matches adr1: " + adr1.hasMatchOf(adr2));
                System.out.println("adr3 matches adr1: " + adr1.hasMatchOf(adr3));
            }catch(Exception e){
                System.err.println(e.getMessage());
            }
        }
    }

Having that, now you can store your IPAddresses in a ArrayList or LinkedList:
ArrayList<IPAddress> addresses = new ArrayList<>();
addresses.add(new IPAddress("8.8.8.8"));
addresses.add(new IPAddress("198.252.206.16"));

IPAddress mask = new IPAddress("20-200.200-255.100-255.0-255");
for (IPAddress addr : addresses){
    if (mask.hasMatchOf(addr)){
        ...
    }else{
        ..
    }
}

