- 阅读权限
- 255
- 威望
- 1 级
- 论坛币
- 49655 个
- 通用积分
- 55.9937
- 学术水平
- 370 点
- 热心指数
- 273 点
- 信用等级
- 335 点
- 经验
- 57805 点
- 帖子
- 4005
- 精华
- 21
- 在线时间
- 582 小时
- 注册时间
- 2005-5-8
- 最后登录
- 2023-11-26
|
19楼
ReneeBK(未真实交易用户)
发表于 2017-8-7 04:02:48
- Example 4-13. Convert an IntStream to an int array
- int[] intArray = IntStream.of(3, 1, 4, 1, 5, 9).toArray();
- // or
- int[] intArray = IntStream.of(3, 1, 4, 1, 5, 9).toArray(int[]::
- The first demo uses the default form of toArray, which returns Object[]. The
- second uses an IntFunction<int[]> as a generator, which creates an int[]
- of the proper size and populates it.
- The fact that any of these approaches is necessary is yet another consequence
- of the original decision in Java to treat primitives differently from objects,
- complicated by the introduction of generics. Still, using boxed or mapToObj is
- easy enough once you know to look for them.
复制代码
|
|