/**
* 书本:《Thinking In Java》
* 功能:用java标准库里面的静态函数调用,复制数组
* 文件:CopyingArrays.java
* 时间:2015年4月30日07:42:44
* 作者:cutter_point
*/
package Lesson16Arrays;
import static net.mindview.util.Print.*;
import java.util.Arrays;
public class CopyingArrays
{
public static void main(String[] args)
{
int[] i = new int[7];
int[] j = new int[10];
//吧这两个数组分别填充为47和99
Arrays.fill(i, 47);
Arrays.fill(j, 99);
//输出这两个
print("i = " + Arrays.toString(i));
print("j = " + Arrays.toString(j));
//复制数组,参数分别是
// * @param src the source array.
// * @param srcPos starting position in the source array.
// * @param dest the destination array.
// * @param destPos starting position in the destination data.
// * @param length the number of array elements to be copied.
System.arraycopy(i, 0, j, 0, i.length);
}
}
输出:
i = [47, 47, 47, 47, 47, 47, 47] obj1
j = [99, 99, 99, 99, 99, 99, 99, 99, 99, 99] obj1
本文介绍了如何利用Java标准库中的静态函数实现数组复制,并通过示例代码展示了具体操作过程。
1315

被折叠的 条评论
为什么被折叠?



