Java #36: Example of how to use Java’s copyOf function

//Programmer: Akinwale Owi
//Company: Dagba Computers
//Program Purpose: Use the copyOf function on an array

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)
{
//Array that we will copy
int [] originalArray = {4, 86, 999, 2000};

//Array we will copy originalArray to later
int [] pseudoArray = {4000, 8600, 9, 66};

//Printing out originalArray values
for (int a = 0; a < originalArray.length; a++)
{
System.out.println("Current Original Array Values: " + originalArray[a]);
}
//Printing out pseudoArray values
for (int b = 0; b < pseudoArray.length; b++)
{
System.out.println("Pseudo Array Values: " + pseudoArray[b]);
}

//Copying originalArray Values into pseduoArray
pseudoArray = Arrays.copyOf(originalArray, originalArray.length);

//Printing out the new values of pseudoArray
for (int c = 0; c < pseudoArray.length;c++)
{
System.out.println("Current Values of PseudoArray: "+ pseudoArray[c]);
}

}//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: