public static List<Integer> parseNumericList(String string){
  ArrayList<Integer> list=new ArrayList<>();
  Pattern ranges=Pattern.compile("(?<Range>(\\d+\\s*-\\s*\\d+))");
  Matcher m=ranges.matcher(string);
  while (m.find()) {
    String range=m.group("Range");
    string=string.replace(range,"");
    parseNumericRange(range,list);
  }
  String[] numbers=string.split("\\D+");
  for (int i=0; i < numbers.length; ++i) {
    String number=numbers[i];
    if (!number.isEmpty()) {
      list.add(Integer.valueOf(number));
    }
  }
  Collections.sort(list);
  return list;
}

public static List < Integer > parseNumericList ( String string ) { ArrayList < Integer > list = new ArrayList < > ( ) ; Pattern ranges = Pattern . compile ( "(?<Range>(\\d+\\s*-\\s*\\d+))" ) ; Matcher m = ranges . matcher ( string ) ; while ( m . find ( ) ) { String range = m . group ( "Range" ) ; string = string . replace ( range , "" ) ; parseNumericRange ( range , list ) ; } String [ ] numbers = string . split ( "\\D+" ) ; for ( int i = 0 ; i < numbers . length ; ++ i ) { String number = numbers [ i ] ; if ( ! number . isEmpty ( ) ) { list . add ( Integer . valueOf ( number ) ) ; } } Collections . sort ( list ) ; return list ; }
converts a natural language list of numerals into a list of integers . sample input of " 10 , 20 , 20 , 303 , 50 , 1012 - 1014 . 1 - 2 , 5 - - - 5 " would produce [ 1 , 2 , 5 , 10 , 20 , 20 , 50 , 303 , 1012 , 1013 , 1014 ] .
