Skip to main content
2 of 4
Included `String[]` as possible result option.
AJNeufeld
  • 34k
  • 5
  • 39
  • 101

As of Java-9, there exists IntStream.html#iterate(seed, hasNext, next)

If you are trying to get a comma separated list of speeds, use:

String speeds = IntStream.iterate(lower, i -> i <= upper, i -> i + step)
                         .mapToObj(Integer::toString)
                         .collect( Collectors.joining( "," ) );

If you just want the integer array of speeds:

int[] speeds = IntStream.iterate(lower, i -> i <= upper, i -> i + step).toArray();

Or, if you want the array of speeds as Strings:

String[] allSpeedsAsArray = IntStream.iterate(lower, i -> i <= upper, i -> i + step)
                                     .mapToObj(Integer::toString)
                                     .toArray();
AJNeufeld
  • 34k
  • 5
  • 39
  • 101