This thread is pretty old, but you might also think of a recursive solution that passes StringBuilder to fill. This prevents any back processing, etc. You just need to design your iteration with recursion and carefully solve the exit condition.
public class Test { public static void main(String[] args) { StringBuilder sb = new StringBuilder(); doRecursive(sb, 100, 0); System.out.println(sb.toString()); } public static void doRecursive(StringBuilder sb, int limit, int index) { if (index < limit) { doRecursive(sb, limit, index + 1); sb.append(Integer.toString(index)); } } }
Benjamin Jan 04 '14 at 2:01 a.m. 2014-01-04 14:01
source share