Results 1 to 1 of 1
Thread: Doubling the size of an array
-
Doubling the size of an array
Java Code: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; } }"The sole cause of man’s unhappiness is that he does not know how to stay quietly in his room." - Blaise Pascal
Similar Threads
-
Changing size of Array
By ravian in forum New To JavaReplies: 3Last Post: 06-05-2012, 08:17 PM -
String max size
By eva in forum New To JavaReplies: 0Last Post: 01-31-2008, 02:29 PM -
Array size declaration
By JT4NK3D in forum New To JavaReplies: 3Last Post: 01-18-2008, 10:37 PM -
how to set an image size
By valery in forum New To JavaReplies: 1Last Post: 08-06-2007, 08:27 PM -
Maximum size of an array
By Hasan in forum New To JavaReplies: 1Last Post: 05-20-2007, 11:11 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks