报错原因
在使用stream用法最后 toarray()方法返回的是Object[],强转成string[] 就会报错。
解决方法:
1.取出Object[],然后创建新的string[]进行for循环赋值
有另一种方法,ex:
String[] array = areaList.toArray(new String[areaList.size()]);
这种也是可以,但是不适用于stream流,因为
reason: no instance(s) of type variable(s) A exist so that String[] conforms to IntFunction<A[]>
原因:不存在类型变量 A 的实例,因此 String[] 符合 IntFunction<A[]>。
用惯了stream 写for循环觉得太麻烦?所以优雅的方式第二种如下
2.用 ,分割转成string 然后再分隔转成string[]
仅此记录