Gil*_*oot 0 java arrays integer java-stream
我有这个数组:
Integer[] originalItems = itemsArray.stream()
.distinct()
.sorted()
.toArray(Integer[]::new);
Run Code Online (Sandbox Code Playgroud)
我想返回它 asint[]而不是 as Integer[]。
我试图打电话,.toArray(int[]::new)但我收到此错误:
不存在类型变量 A 的实例,因此 int[] 符合 A[]
.mapToInt(Integer::intValue).toArray();
Run Code Online (Sandbox Code Playgroud)
代替
.toArray(Integer[]::new);
Run Code Online (Sandbox Code Playgroud)
因为
<A> A[] toArray(IntFunction<A[]> generator);
Run Code Online (Sandbox Code Playgroud)
不适用于原始类型。
| 归档时间: |
|
| 查看次数: |
51 次 |
| 最近记录: |