数组拆分成两部分,而在Java中环 [英] Split array into two parts without for loop in java

查看:248
本文介绍了数组拆分成两部分,而在Java中环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有大小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?

推荐答案

您可以使用<一个href=\"https://docs.oracle.com/javase/8/docs/api/java/lang/System.html#arraycopy-java.lang.Object-int-java.lang.Object-int-int-\"><$c$c>System.arraycopy().

int[] source = new int[1000];

int[] part1 = new int[500];
int[] part2 = new int[500];

System.arraycopy(source, 0, part1, 0, part1.length);
System.arraycopy(source, part1.length, part2, 0, part2.length);

这篇关于数组拆分成两部分,而在Java中环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆