java 数组扩容

package day519;

public interface TestArray {
	public static void main(String[] args) {
		int[] a = {1,2,3};
		//数组特点:长度固定  类型相同
		int[] as = expand(a);
		for (int i = 0; i < as.length; i++) {
			System.out.println(as[i]);
		}
	}
	//数组扩容的函数 扩容哪一个数组
	public static int[] expand(int[] a) {
		int[] as = new int[a.length*2];
		for(int i=0;i<a.length;i++) {
			as[i]=a[i];
		}
		return as;
	}
}
//数组扩容

你可能感兴趣的:(笔记)