how can i form a string containing number from 0 to n?

Use IntStream and StringBuilder:

int n = 5;
String string = IntStream.rangeClosed(0, n)
     .collect(StringBuilder::new, StringBuilder::append, StringBuilder::append)

However, for this particular case it’s better to use a for-loop with StringBuilder.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top