Java Number Range Create range(String second, String first)

Here you can find the source of range(String second, String first)

Description

range

License

Open Source License

Declaration

private static String range(String second, String first) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    private static String range(String second, String first) {
        try {//  w w  w . j a v a  2 s. co  m
            int from = Integer.parseInt(first);
            int to = Integer.parseInt(second);
            if (from > to) {
                int temp = from;
                from = to;
                to = temp;
            } else if (from == to)
                return String.valueOf(from);
            StringBuilder sb = new StringBuilder(String.valueOf(from));
            for (int i = from + 1; i <= to; ++i)
                sb.append(',').append(i);
            return sb.toString();
        } catch (NumberFormatException e2) {
            throw new IllegalArgumentException(first + " .. " + second);
        }
    }
}

Related

  1. range(Integer from, Integer to)
  2. range(long array[])
  3. range(long start, long end)
  4. range(String field, int start, int end)
  5. range(String input[], int beginIndex, int endIndex)
  6. range(T val, T min, T max)
  7. RangeConvert(float start, float end, float newStart, float newEnd, float value)