I\'m trying to print this loop without the last comma. I\'ve been Googling about this and from what i\'ve seen everything seems overcomplex for such a small problem. Surely
Java 8:
IntStream.rangeClosed(a, b)
.collect(Collectors.joining(","));
If you want to perform interleaving actions:
Java 8:
IntStream.rangeClosed(a, b)
.peek(System.out::print)
.limit(b - a) // [a:(b-1)]
.forEach(i -> System.out.print(","));
Java 9:
IntStream.rangeClosed(a, b)
.peek(System.out::print)
.takeWhile(i -> i < b) // [a:(b-1)]
.forEach(i -> System.out.print(","));