📄 arraycopy.java
字号:
//==============================================================
// ArrayCopy.java - Demonstrate array copying techniques
//
// Java学习源代码检索系统 Ver 1.0 20031015 免费正式版
// 版权所有: 中国IT认证实验室(www.ChinaITLab.com)
// 程序制作: ChinaITLab网校教研中心
// 主页地址: www.ChinaITLab.com 中国IT认证实验室
// 论坛地址: bbs.chinaitlab.com
// 电子邮件: Java@ChinaITLab.com
//==============================================================
import TestClass; // Import submodule
class ArrayCopy {
// Declare the two arrays
public static int[] apples, oranges;
// Array copy method #1
public static void CopyMethod1() {
System.out.println("\nArray copy method #1");
oranges = apples;
// oranges[0]++; // Enable to change test
TestClass.CompareArrays(apples, oranges);
}
// Array copy method #2
public static void CopyMethod2() {
System.out.println("\nArray copy method #2");
oranges = new int[apples.length];
System.arraycopy(apples, 0, oranges, 0, apples.length);
oranges[0]++; // Enable to change test
TestClass.CompareArrays(apples, oranges);
}
// Array copy method #3
public static void CopyMethod3() {
System.out.println("\nArray copy method #3");
oranges = (int[])apples.clone();
// oranges[0]++; // Enable to change test
TestClass.CompareArrays(apples, oranges);
}
public static void main(String args[]) {
// Construct and initialize the first array
apples = new int[8];
for (int i = 0; i < apples.length; i++)
apples[i] = (int)(Math.random() * 100);
// Copy three ways and test each copy
CopyMethod1();
CopyMethod2();
CopyMethod3();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -