you can also achive this with Stream :
IntStream.rangeClosed(1, 10) .forEach(i -> { System.out.println( Collections.nCopies(i, String.valueOf(i)) .stream() .collect(Collectors.joining(" ")) ); });