有简单的解决方案可以连接两个String[]或Integer[]在java中Streams.因为int[]经常使用.连接两个有什么简单的方法int[]吗?
这是我的想法:
int[] c = {1, 34};
int[] d = {3, 1, 5};
Integer[] cc = IntStream.of(c).boxed().toArray(Integer[]::new);
Integer[] dd = Arrays.stream(d).boxed().toArray(Integer[]::new);
int[] m = Stream.concat(Stream.of(cc), Stream.of(dd)).mapToInt(Integer::intValue).toArray();
System.out.println(Arrays.toString(m));
>>
[1, 34, 3, 1, 5]
Run Code Online (Sandbox Code Playgroud)
它可以工作,但它实际上转换int[]为Integer[],然后再转换Integer[]回来int[].