Source Code : Doubling the size of an array
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
Doubling the size of an array

public class DoubleArray {
public static void main(String args[]) {
int a1[] = { 1, 2, 3, 4, 5 };
int a2[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
System.out.println("Original size: " + a1.length);
System.out.println("New size: " + doubleArray(a1).length);
System.out.println("Original size: " + a2.length);
System.out.println("New size: " + doubleArray(a2).length);
}
static int[] doubleArray(int original[]) {
int length = original.length;
int newArray[] = new int[length * 2];
System.arraycopy(original, 0, newArray, 0, length);
return newArray;
}
}
Thank with us