divide a range of numbers into groups of 10, 100, 1000, 10000 and so on
Even the “extended version” does not handle the cases where start and end have more than 6 trailing zeros in common. Instead of hard-coding those ranges and a long if/else if/... statement you can determine the largest fitting range dynamically in a loop:

for (long i = st; i &lt;= en; ) {
    // Determine `range` as largest power of 10 with `i % range == 0`
    // and `i + range - 1 &lt;= en`:
    int range = 1;
    while (range &lt;= i &amp;&amp; i % range == 0 &amp;&amp; i + range - 1 &lt;= en) {
        range *= 10;
    }
    range /= 10;

    System.out.println(i / range); 
    i += range;
}


Removing common zeros/nines is more efficiently done in integer arithmetic instead of string manipulation:

while (st % 10 == 0 &amp;&amp; en % 10 == 9) {
    st /= 10;
    en /= 10;
}


I would move the computation from main() into a separate function and separate it from the I/O. That increases the clarity of the program and allows to add test cases more easily. In a comment you said that you need the result as List&lt;String&gt;:

public static List&lt;String&gt; computePrefixes(long start, long end) {
    List&lt;String&gt; prefixes = new ArrayList&lt;String&gt;();

    while (start % 10 == 0 &amp;&amp; end % 10 == 9) {
        start /= 10;
        end /= 10;
    }

    for (long i = start; i &lt;= end; ) {
        // Determine `range` as largest power of 10 with `i % range == 0`
        // and `i + range - 1 &lt;= en`:
        int range = 1;
        while (range &lt;= i &amp;&amp; i % range == 0 &amp;&amp; i + range - 1 &lt;= end) {
            range *= 10;
        }
        range /= 10;

        prefixes.add(String.valueOf(i / range));
        i += range;
    }

    return prefixes;
}

public static void main(String[] args) {
    String start = "1230000";
    String end   = "1285999";

    long st = Long.parseLong(start);
    long en = Long.parseLong(end);
    List&lt;String&gt; prefixes = computePrefixes(st, en);
    System.out.println(prefixes);
}


You may also want to check the validity of the parameters (1 &lt;= start &lt;= end).

Finally note that there is still a problem with numbers close to Long.MAX_VALUE because the calculations can overflow. If that is an issue then the range calculations and comparisons have to be done more carefully:

public static List&lt;String&gt; computePrefixes(long start, long end) {
    List&lt;String&gt; prefixes = new ArrayList&lt;String&gt;();

    while (start % 10 == 0 &amp;&amp; end % 10 == 9) {
        start /= 10;
        end /= 10;
    }

    for (long i = start; ; ) {
        // Determine `range` as largest power of 10 with `i % range == 0`
        // and `i + range - 1 &lt;= end`:
        int range = 1;
        while (range &lt;= Long.MAX_VALUE / 10 &amp;&amp; range &lt;= i &amp;&amp; i % range == 0 &amp;&amp; range - 1 &lt;= end - i) {
            range *= 10;
        }
        range /= 10;

        prefixes.add(String.valueOf(i / range));
        if (i == end) {
            break;
        }
        i += range;
    }

    return prefixes;
}