Home Tutorial Java Corejava Java copyOf example


Share on Google+Share on Google+
Java copyOf example
Posted on: April 9, 2010 at 12:00 AM
This tutorial demonstrate the copyOf method. In the below listed program you will see how copyOf method is help in copy one array variable's values into a new array variable.


The copyOf method copies the specified array, truncating or padding with zeros so that the copy has the specified length. The result of this method allow to have the same of content in newly copied array.


import java.util.Arrays;

public class CopyOfExample {
  public static void main(String args[]) {
    String str[] "a""b""c" };
    String copy[] = Arrays.copyOf(str, 3);
    System.out.printf("value of str \t\t%s\n", Arrays.toString(str));
    System.out.printf("Value of copy\t\t%s", Arrays.toString(copy));



Related Tags for Java copyOf example :

Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 9, 2010

Recommend the tutorial

Advertisements Advertisements