java - What is the best way to get a range of results? -


i have program can run command line -r specify range of results return. -r takes 1 argument of form n:n.

seeing though n:n 1-5 or 10000-500000, best way of values on both sides of :?

after passing arg following -r method started doing following:

private int[] parserangeresults(string range) {    int[] rangeresults = new int[2];     if(!(range.contains(":"))) {       throw new exception("invalid range syntax");    }     string[] numbers = range.split(":")    rangeresults[0] = integer.parseint(numbers[0]);    rangeresults[1] = integer.parseint(numbers[2]);     return rangeresults; } 

but think breaks down if puts special characters, or 1000:::::5000, best way of handling this?

the best way check input regular expressions if regex("\\d*-\\d*") matches, output correct. code function

    string regex = "(\\d*):(\\d*)";     pattern checkinput = pattern.compile(regex);      matcher matcherinput = checkinput.matcher(range);      if(matcherinput.matches()){         rangeresults[1] = integer.parseint(matcherinput.group(1));         rangeresults[2] = integer.parseint(matcherinput.group(2));        } 

Comments