jdk提供的数组扩容方法:System.arraycopy
2021-07-13 13:05
                         标签:--   class   copy   apt   方法   下标   jdk   拷贝   tar    package chapter7; /* 	public static void print(int array[]) { jdk提供的数组扩容方法:System.arraycopy 标签:--   class   copy   apt   方法   下标   jdk   拷贝   tar    原文地址:https://www.cnblogs.com/Koma-vv/p/9542463.html
 * jdk提供的扩容方法
 * System.arraycopy
 */
public class TestArrayjdk {
	public static void main(String[] args) {
		// 定义数组
		int[] a = { 2, 8, 6, 5, 3 };
		// 定义一个扩容数组
		int[] b = new int[a.length];
		// 用jdk提供的方法存储数组
		/*
		 * 第一个参数:Object src: 原数组---a
		 * 第二个参数:int srcPos: 从原数组中的哪个下标位置开始拷贝
		 * 第三个参数:Object dest: 目标数组---b
		 * 第四个参数:int destPos:从目标数组的那个下标位置开始放
		 * 第五个参数:int length:拷贝的元素的个数
		 */
		System.arraycopy(a, 0, b, 0, a.length);
		//
		// a = b;//可以省略该步骤
		print(a);
	}
		for (int i = 0; i 			System.out.println(array[i]);
		}
	}
}
上一篇:进程与线程
下一篇:springmvc框架原理分析
文章标题:jdk提供的数组扩容方法:System.arraycopy
文章链接:http://soscw.com/index.php/essay/104639.html