问题
https://stackoverflow.com/a/23675131/14731 provides a nice solution for generating a list of contiguous integers. Seeing as JDK8 does not provide a ShortStream
class, how would you generate a list of contiguous shorts?
I'm looking for something along the lines of:
List<Short> range = ShortStream.range(0, 500).boxed().collect(Collectors.toList());
where the output contains a list of shorts, from 0 to 500 inclusive.
回答1:
List<Short> range =
IntStream.range(0, 500).mapToObj(i -> (short) i).collect(Collectors.toList());
来源:https://stackoverflow.com/questions/30789966/populating-a-list-with-a-contiguous-range-of-shorts