Java String Extract extractNumberFromInput(String command)

Here you can find the source of extractNumberFromInput(String command)

Description

Returns ArrayList which contains not repeated input numbers

License

Open Source License

Declaration

private static ArrayList<Integer> extractNumberFromInput(String command) 

Method Source Code


//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;
    }
}

Related

  1. extractItems(String items)
  2. extractJobId(String line)
  3. extractKeyCodes(String codes)
  4. extractLines(String data, int tabWidth)
  5. extractNoPublicDomains(String domains)
  6. extractNumbers(String text)
  7. extractPacket(String serverPacket)
  8. extractParameters(String uri)
  9. extractParamsFromUriTemplateFragment(String value)