Here you can find the source of extractNumberFromInput(String command)
private static ArrayList<Integer> extractNumberFromInput(String command)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; public class Main { /**/*from w w w. j a v a 2 s .c om*/ * Returns ArrayList which contains not repeated input numbers */ private static ArrayList<Integer> extractNumberFromInput(String command) { String[] splittedStringIndexes = command.trim().replace(" ", "").split(","); ArrayList<Integer> intIndexList = new ArrayList<Integer>(); for (String index : splittedStringIndexes) { if (index.contains("to")) { String[] range = index.split("to"); int start = Integer.parseInt(range[0]); int end = Integer.parseInt(range[1]); for (int i = start; i <= end; i++) { if (!intIndexList.contains(i)) { intIndexList.add(i); } } } else { if (!intIndexList.contains(Integer.parseInt(index))) { intIndexList.add(Integer.parseInt(index)); } } } return intIndexList; } }