I'll have two integers and will want to generate an array of those two numbers and all the numbers in between as strings (I know the ranges are small).
i.e. given 1004
and 1008
. I'd generate "1004", "1005", "1006", "1007", "1008"
I'm familiar with C# and there I'd do something like
var start = 1004; var end = 1008; var fullRange = Enumerable.Range(start, end - start + 1) .Select(i => i.ToString()) .ToArray();
I need to do this in Java 8 and have come up with
String[] fullRange = IntStream.range(start, end+1)
.mapToObj(String::valueOf)
.toArray(String[]::new);
But I'm new to Java and wondered if there's a better / more-readable way to achieve this in Java. Am I just cramming C# into Java?