1

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.

Community
  • 1
  • 1
Gili
  • 81,444
  • 90
  • 364
  • 657

1 Answers1

5
List<Short> range = 
    IntStream.range(0, 500).mapToObj(i -> (short) i).collect(Collectors.toList());
JB Nizet
  • 657,433
  • 87
  • 1,179
  • 1,226
  • Good answer. Please take a look at this follow-up question: http://stackoverflow.com/q/30790665/14731 – Gili Jun 11 '15 at 20:21