在java中没有for循环的情况下将数组分成两部分 [英] Split array into two parts without for loop in java
本文介绍了在java中没有for循环的情况下将数组分成两部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个大小为 300000 的数组,我希望它把它分成 2 个相等的部分.这里有什么方法可以用来实现这个目标吗?
I have an array of size 300000 and i want it to split it into 2 equal parts. Is there any method that can be used here to achieve this goal?
它会比for循环操作更快还是不会对性能造成影响?
Will it be faster than the for-loop operation or it will cause no effect on performance?
推荐答案
您可以使用 System.arraycopy()
.
You can use System.arraycopy()
.
int[] source = new int[1000];
int[] part1 = new int[500];
int[] part2 = new int[500];
// (src , src-offset , dest , offset, count)
System.arraycopy(source, 0 , part1, 0 , part1.length);
System.arraycopy(source, part1.length, part2, 0 , part2.length);
这篇关于在java中没有for循环的情况下将数组分成两部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文