Java tutorial
//package com.java2s; //License from project: LGPL import java.util.ArrayList; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static int[] parseIntegerList(String list, int minValue, int maxValue) { ArrayList tmpList = new ArrayList(); Pattern p = Pattern.compile("(\\d*)-(\\d*)"); String[] a = list.replace(',', ' ').split("\\s+"); int i = a.length; for (int i$ = 0; i$ < i; ++i$) { String token = a[i$]; try { if (token.matches("\\d+")) { tmpList.add(Integer.valueOf(Integer.parseInt(token))); } else { Matcher e = p.matcher(token); if (e.matches()) { String a1 = e.group(1); String b = e.group(2); int min = a1.equals("") ? minValue : Integer.parseInt(a1); int max = b.equals("") ? maxValue : Integer.parseInt(b); for (int i1 = min; i1 <= max; ++i1) { tmpList.add(Integer.valueOf(i1)); } } } } catch (NumberFormatException var15) { ; } } if (minValue <= maxValue) { int var16 = 0; while (var16 < tmpList.size()) { if (((Integer) tmpList.get(var16)).intValue() >= minValue && ((Integer) tmpList.get(var16)).intValue() <= maxValue) { ++var16; } else { tmpList.remove(var16); } } } int[] var17 = new int[tmpList.size()]; for (i = 0; i < var17.length; ++i) { var17[i] = ((Integer) tmpList.get(i)).intValue(); } return var17; } }