Java #37: Using the copyOf function to copy and increase the size of an Array

Source Code Photo

Actual Source Code:

//Programmer: Akinwale Owi
//Company: Dagba Computers
//Program Purpose:Increase the size of an Array using the copyOf function

package dagbacomputers;

/**
*
* @author Akin
*/

//imports
import java.util.*;
import java.util.Arrays;

public class DagbaComputers {

/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
//Creating the original Array
int [] originalArray = {8, 29, 3000};

//printing out the original array to test
for (int i = 0; i < originalArray.length; i++)
{
System.out.println("Original Array Values: " + originalArray[i]);
}

//Creating a copy of originalArray
int [] pseudoArray = Arrays.copyOf(originalArray, 10);

//Printing out all the values of the new array
for (int j = 0; j < pseudoArray.length; j++)
{
System.out.println("Pseudo Values: " + pseudoArray[j]);
//Should have all the same values as originalArray just some extra zeroes for the new values
}

}//end of main
}//End of DagbaComputers Class

———–End of Program—————
——————————Output——————-

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: