Array Copy Demo : Array « Collections Data Structure « Java






Array Copy Demo

Array Copy Demo
     
/*
 * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * -Redistribution of source code must retain the above copyright notice, this
 *  list of conditions and the following disclaimer.
 *
 * -Redistribution in binary form must reproduce the above copyright notice,
 *  this list of conditions and the following disclaimer in the documentation
 *  and/or other materials provided with the distribution.
 *
 * Neither the name of Sun Microsystems, Inc. or the names of contributors may
 * be used to endorse or promote products derived from this software without
 * specific prior written permission.
 *
 * This software is provided "AS IS," without a warranty of any kind. ALL
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
 * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
 * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN")
 * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
 * AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
 * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
 * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
 * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
 * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
 *
 * You acknowledge that this software is not designed, licensed or intended
 * for use in the design, construction, operation or maintenance of any
 * nuclear facility.
 */

public class ArrayCopyDemo {
  public static void main(String[] args) {
    char[] copyFrom = { 'd', 'e', 'c', 'a', 'f', 'f', 'e', 'i', 'n', 'a',
        't', 'e', 'd' };
    char[] copyTo = new char[7];

    System.arraycopy(copyFrom, 2, copyTo, 0, 7);
    System.out.println(new String(copyTo));
  }
}
           
         
    
    
    
    
  








Related examples in the same category

1.Initialize a static array
2.Initialization and re-assignment of arraysInitialization and re-assignment of arrays
3.Doubling the size of an arrayDoubling the size of an array
4.Timing array loop performance
5.Array 2DArray 2D
6.Can you change the .length of an array
7.Show Two-Dimensional Array of Objects
8.ArrayListDemo done over using an ArrayList
9.Array Hunt game
10.Multi Dimension Array
11.Clone Array
12.Associates keys with valuesAssociates keys with values
13.Arrays of primitives
14.Creating arrays with new
15.Array initialization
16.Creating an array of nonprimitive objects
17.Create multidimension arraysCreate multidimension arrays
18.Initializing Array ValuesInitializing Array Values
19.Creating a Two-Dimensional Array
20.Initializing a Two Dimensional ArrayInitializing a Two Dimensional Array
21.Using the length VariableUsing the length Variable
22.Triangular array
23.Grow arrayGrow array
24.Define array for class Define array for class
25.String array and output to consoleString array and output to console
26.Multiply two matrices
27.Array Of Arrays Demo 2Array Of Arrays Demo 2
28.Copying Elements from One Array to Another
29.Java program to demonstrate multidimensional arraysJava program to demonstrate multidimensional arrays
30.Extend the size of an array
31.Copy an array
32.Initialize multidimensional array
33.Get array upperbound
34.To get the number of dimensions
35.Resize an array, System.arraycopy()
36.Dump array content: Convert the array to a List and then convert to String
37.java.utils.Arrays provides ways to dump the content of an array.
38.Dump multi-dimensional arrays
39.Use the new shorthand notation to iterate through an array
40.Create a repeated sequence of character
41.Reverse array elements order
42.Convert array of primitives into array of objects
43.Array Initializers
44.Reinitializes a byte array
45.Reinitializes an int array
46.Sum all elements in the array
47.Sums an array of numbers log(x1)...log(xn)
48.A class to iterate over all permutations of an array.
49.Palidrome Array
50.Set of utilities used to manipulate arrays.
51.ArrayUtils provides static methods for manipulating arrays when using a tool such as java.util.ArrayList is inconvenient.
52.Array Util
53.clone two dimensional array