Populating a List with a contiguous range of shorts

不打扰是莪最后的温柔 提交于 2019-12-13 17:21:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!